2016年12月31日 星期六

[研究] PHP 7.1.0 (tar.gz) 安裝 (CentOS 7.3)

[研究] PHP 7.1.0 (tar.gz) 安裝 (CentOS 7.3)

2016-12-31

yum -y install  gcc  libxml2-devel  libxml2
cd  /usr/local/src
wget  http://tw1.php.net/distributions/php-7.1.0.tar.gz
tar  zxvf  php-7.1.0.tar.gz
cd  php-7.1.0/
./configure
make
make test
make install

其中

[root@localhost php-7.1.0]# make  test
... (略)
=====================================================================
WARNED TEST SUMMARY
---------------------------------------------------------------------
Bug #72663: Create an Unexpected Object and Don't Invoke __wakeup() in Deserialization [ext/standard/tests/strings/bug72663_3.phpt] (warn: XFAIL section but test passes)
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.  You can then email it to qa-reports@lists.php.net later.
Do you want to send this report now? [Yns]:
Please enter your email address.
(Your address will be mangled so that it will not go out on any
mailinglist in plain text):
sh: autoconf: command not found

Posting to http://qa.php.net/buildtest-process.php

Thank you for helping to make PHP better.
[root@localhost php-7.1.0]# make


[root@localhost php-7.1.0]# make install
... (略)
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/usr/local/src/php-7.1.0/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers:           /usr/local/include/php/ext/pdo/
[root@localhost php-7.1.0]#

測試

[root@localhost php-7.1.0]# php -v
PHP 7.1.0 (cli) (built: Dec 31 2016 20:23:54) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
[root@localhost php-7.1.0]#


(完)

[研究] Active Directory (AD) 網域服務安裝 (Windows Server 2016)

[研究] Active Directory (AD) 網域服務安裝 (Windows Server 2016)

2016-12-31























(完)

相關

安裝 Active Directory 網域服務 (層級 100)
https://technet.microsoft.com/library/hh472162#BKMK_PS

[研究] Active Directory (AD) 網域服務安裝 (Windows Server 2016)
http://shaurong.blogspot.com/2016/12/active-directory-ad-windows-server-2016.html

[研究] Active Directory (AD) 網域服務安裝 (Windows Server 2012 R2)
http://shaurong.blogspot.tw/2015/05/active-directory-windows-server-2012-r2.html

[研究] Active Directory (AD) 網域服務安裝 (Windows Server 2008 R2)
http://shaurong.blogspot.tw/2015/11/active-directory-ad-windows-server-2008.html

[研究] [C#] 使用 GemBox.Spreadsheet 讀取LibreOffice、OpenOffice試算表(Calc) 檔案 (.ods)

[研究] [C#] 使用 GemBox.Spreadsheet 41.3.30.1038讀取 LibreOffice 5.1.6、OpenOffice 4.1.3 試算表(Calc) 檔案 (.ods)

2016-12-30

這是商業付費軟體,雖然有30天試用版,但功能有限制
Maximum number of rows per sheet is 150.
Maximum number of sheets per workbook is 5.

參考

How to Access XLS, XLSX, ODS and CSV files from your .NET applications?
https://www.gemboxsoftware.com/spreadsheet/articles/access-xls-xlsx-ods-csv-net

Excel Library for C# and VB.NET applications
https://www.gemboxsoftware.com/spreadsheet/examples/c-sharp-vb-net-excel-library/601

Visual Studio 2015 with Update 3

Test.ods 內容如下,放在 D:\CodeTemp\ODSDemo3\ODSDemo3\bin\Debug 目錄。










WinForm 的 Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

using GemBox.Spreadsheet;
// https://www.gemboxsoftware.com/spreadsheet/free-version
//Limitations
//
//GemBox.Spreadsheet Free delivers the same performance and set of features as the Professional version.However, the following limitations are imposed:
//
//Maximum number of rows per sheet is 150.
//Maximum number of sheets per workbook is 5.

namespace ODSDemo3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "ods files (*.ods)|*.ods|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        label1.Text = openFileDialog1.FileName; // 包含路徑
                        string inputFilePath = openFileDialog1.FileName; // 包含路徑

                        //var workbook = ExcelFile.Load("Workbook.ods", odsLoadOptions);
                        var workbook = ExcelFile.Load(inputFilePath);

                        // Select active worksheet.
                        var worksheet = workbook.Worksheets.ActiveWorksheet;

                        // Display the value of first cell in MessageBox.
                        MessageBox.Show(worksheet.Cells["A1"].GetFormattedValue());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
}


執行結果

如果沒有下面這行

GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

會出現下面圖片的錯誤

Free version serial key is: FREE-LIMITED-KEY

(完)

[研究] Apache 2.4.25 (https) + OpenSSL 1.1.0c安裝(CentOS 7.3)

[研究] Apache 2.4.25 (https) + OpenSSL 1.1.0c安裝(CentOS 7.3)

2016-12-30
2017-03-29
2017-03-30

CentOS 7.3 的 yum 目前只能安裝 httpd 到 2.4.6 版,如果想要安裝 2.4.25版

[root@localhost conf]# yum list | grep httpd.x86_64
httpd.x86_64                               2.4.6-45.el7.centos         base
libmicrohttpd.x86_64                       0.9.33-2.el7                base

[root@localhost conf]# yum list | grep openssl.x86_64
openssl.x86_64                             1:1.0.1e-60.el7             @anaconda
apr-util-openssl.x86_64                    1.5.2-6.el7                 base
xmlsec1-openssl.x86_64                     1.2.20-5.el7                base
[root@localhost conf]#

開始安裝、啟動

#先安裝 yum版的OpenSSL
su  root
yum  -y  install  openssl  openssl-devel  apr  apr-devel apr-util apr-util-devel  pcre pcre-devel  gcc

#安裝新版httpd (不可先安裝新版 openssl-1.1.0c.tar.gz,實際測試失敗)
cd  /usr/local/src
wget  http://apache.stu.edu.tw//httpd/httpd-2.4.25.tar.gz
tar  xvfz httpd-2.4.25.tar.gz
cd  httpd-2.4.25
./configure --enable-ssl --enable-cgid --enable-rewrite --enable-so
make
make install

#安裝新版openssl
yum  -y  install   gcc   zlib   zlib-devel
cd  /usr/local/src
wget  http://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar xzvf  openssl-1.1.0c.tar.gz
cd  openssl-1.1.0c
./config  shared  zlib
make
make  install
mv  -f   /usr/bin/openssl /usr/bin/openssl.bak
mv  -f  /usr/include/openssl   /usr/include/openssl.bak
ln  -s  /usr/local/bin/openssl   /usr/bin/openssl
ln  -s  /usr/local/include/openssl   /usr/include/openssl
echo   “/usr/local/lib64”   >>   /etc/ld.so.conf
ldconfig  -v
openssl  version
ln  -s  /usr/local/lib64/libssl.so.1.1  /usr/lib64/libssl.so.1.1

ln  -s  /usr/local/lib64/libcrypto.so.1.1  /usr/lib64/libcrypto.so.1.1
openssl  version

#再編譯一次 httpd
cd  httpd-2.4.25
./configure --enable-ssl --enable-cgid --enable-rewrite --enable-so
make
make install

#設定 httpd 用 openssl
echo  "LoadModule ssl_module modules/mod_ssl.so"  >>  /usr/local/apache2/conf/httpd.conf
echo  "LoadModule socache_shmcb_module modules/mod_socache_shmcb.so"  >>  /usr/local/apache2/conf/httpd.conf
echo  "Include conf/extra/httpd-ssl.conf"  >>  /usr/local/apache2/conf/httpd.conf

#產生 ssl key (這邊不可一次把 4 行貼到 putty 去執行,要一行執行完畢後再執行另一行)
cd  /usr/local/apache2/conf
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

#啟動 httpd
/usr/local/apache2/bin/httpd  -k  restart






PS :
如果要使用 AES256 加密,會要求輸入至少4位數的密碼,而且啟動 httpd 時候也會要求輸入,有些麻煩。

[root@localhost conf]# openssl genrsa -aes256 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.............................................................+++
....................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
139640097662880:error:28069065:lib(40):UI_set_result:result too small:ui_lib.c:869:You must type in 4 to 8191 characters
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
[root@localhost conf]#


[root@localhost conf]# /usr/local/apache2/bin/httpd -k restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
[root@localhost conf]#

********************************************************************************

2017-03-29 重新做,補測試

[root@localhost ~]# openssl version
OpenSSL 1.1.0c  10 Nov 2016
[root@localhost ~]#

********************************************************************************

2017-03-29

考慮用 phpinfo(); 測 openssl 版本,好像有點問題,待研究

[root@localhost ~]# yum -y install httpd php

[root@localhost ~]# systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-03-29 23:12:42 CST; 18s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 96547 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 96543 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 96543 (code=exited, status=1/FAILURE)

Mar 29 23:12:42 localhost.localdomain httpd[96543]: (98)Address already in us...
Mar 29 23:12:42 localhost.localdomain httpd[96543]: (98)Address already in us...
Mar 29 23:12:42 localhost.localdomain httpd[96543]: no listening sockets avai...
Mar 29 23:12:42 localhost.localdomain httpd[96543]: AH00015: Unable to open logs
Mar 29 23:12:42 localhost.localdomain systemd[1]: httpd.service: main process...
Mar 29 23:12:42 localhost.localdomain kill[96547]: kill: cannot find process ""
Mar 29 23:12:42 localhost.localdomain systemd[1]: httpd.service: control proc...
Mar 29 23:12:42 localhost.localdomain systemd[1]: Failed to start The Apache ...
Mar 29 23:12:42 localhost.localdomain systemd[1]: Unit httpd.service entered ...
Mar 29 23:12:42 localhost.localdomain systemd[1]: httpd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@localhost ~]#

********************************************************************************

2017-03-30

改成先安裝 httpd 和 php
yum  -y  install  httpd  php
systemctl   start  httpd
systemctl   status  httpd
目前都正常

再照最上面開始安裝,最後出錯了

Getting Private key
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
[root@localhost ~]#

建立一個 /var/www/html/i.php
內容
<?php
phpinfo();
?>
顯示目前 OpenSSL 是 1.0.1e 版


重新啟動 httpd,有問題,待研究

[root@localhost ~]# systemctl restart httpd.services
Failed to restart httpd.services.service: Unit not found.
[root@localhost ~]#

(待研究)

相關

[研究] Apache 2.4.25 (https) + OpenSSL 1.0.1e (yum) 安裝(CentOS 7.3)
http://shaurong.blogspot.com/2016/12/apache-2425-https-openssl-110ccentos-73.html

[研究] Apache HTTPd Web Server 2.4.6 + HTTPS (SSL) yum 安裝 (CentOS 7.2 x64)
http://shaurong.blogspot.com/2016/08/apache-httpd-web-server-246-https-ssl.html

2016年12月30日 星期五

[研究] 檢視 OpenSSL (yum) 的編譯參數 (CentOS 7.3)

[研究] 檢視 OpenSSL (yum) 的編譯參數 (CentOS 7.3)

2016-10-30

只顯示版本

[root@localhost lib64]# openssl version 
OpenSSL 1.0.1e-fips 11 Feb 2013

 顯示版本和編譯參數

[root@localhost lib64]# openssl version -a
OpenSSL 1.0.1e-fips 11 Feb 2013
built on: Sun Nov  6 03:45:24 UTC 2016
platform: linux-x86_64
options:  bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/etc/pki/tls"
engines:  rdrand dynamic
[root@localhost lib64]#

(完)

[研究] OpenSSL 1.1.0c (tar.gz) 安裝 (CentOS 7.3)

[研究] OpenSSL 1.1.0c (tar.gz) 安裝 (CentOS 7.3)

2016-12-30

CentOS 7.3 預設 yum 安裝的 OpenSSL 是 1.0.1e 版,如果想安裝 1.1.0c 版要另想辦法。

[root@localhost ~]# openssl  version
OpenSSL 1.0.1e-fips 11 Feb 2013

[root@localhost ~]# openssl  version  -a
OpenSSL 1.0.1e-fips 11 Feb 2013
built on: Sun Nov  6 03:45:24 UTC 2016
platform: linux-x86_64
options:  bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/etc/pki/tls"
engines:  rdrand dynamic
[root@localhost ~]#

安裝

su  root
yum  -y  install   gcc   zlib   zlib-devel
cd  /usr/local/src
wget  http://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar xzvf  openssl-1.1.0c.tar.gz
cd  openssl-1.1.0c
./config  shared  zlib
make
make  install
mv  /usr/bin/openssl /usr/bin/openssl.bak
mv  /usr/include/openssl   /usr/include/openssl.bak
ln  -s  /usr/local/bin/openssl   /usr/bin/openssl
ln  -s  /usr/local/include/openssl   /usr/include/openssl
echo   “/usr/local/lib64”   >>   /etc/ld.so.conf
ldconfig  -v

openssl  version
ln  -s  /usr/local/lib64/libssl.so.1.1  /usr/lib64/libssl.so.1.1
ln  -s  /usr/local/lib64/libcrypto.so.1.1  /usr/lib64/libcrypto.so.1.1
openssl  version

第一次  openssl  version 會出錯

解決openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory錯誤

這是因為 OpenSSL Libaray 位置不對,解決方法

ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

(完)

相關

[研究] OpenSSL 1.1.0c (tar.gz) 安裝 (CentOS 7.3)
http://shaurong.blogspot.com/2016/12/openssl-110c-targz-centos-73.html

[研究] Apache 2.4.25 (https) + OpenSSL 1.0.1e (yum) 安裝(CentOS 7.3)
http://shaurong.blogspot.com/2016/12/apache-2425-https-openssl-101e-yum.html

[研究] Apache HTTPd Web Server 2.4.6 + HTTPS (SSL) yum 安裝 (CentOS 7.2 x64)
http://shaurong.blogspot.com/2016/08/apache-httpd-web-server-246-https-ssl.html


[研究] Apache 2.4.25 (https) + OpenSSL 1.0.1e (yum) 安裝(CentOS 7.3)

[研究] Apache 2.4.25 (https) + OpenSSL 1.0.1e (yum)安裝(CentOS 7.3)

2016-12-30

CentOS 7.3 的 yum 目前只能安裝 httpd 到 2.4.6 版,如果想要安裝 2.4.25版

[root@localhost conf]# yum list | grep httpd.x86_64
httpd.x86_64                               2.4.6-45.el7.centos         base
libmicrohttpd.x86_64                       0.9.33-2.el7                base

[root@localhost conf]# yum list | grep openssl.x86_64
openssl.x86_64                             1:1.0.1e-60.el7             @anaconda
apr-util-openssl.x86_64                    1.5.2-6.el7                 base
xmlsec1-openssl.x86_64                     1.2.20-5.el7                base
[root@localhost conf]#

開始安裝、啟動

yum  -y  install  openssl-devel  apr-util-devel  pcre-devel  gcc

cd  /usr/local/src
wget  http://apache.stu.edu.tw//httpd/httpd-2.4.25.tar.gz
tar  xvfz httpd-2.4.25.tar.gz
cd  httpd-2.4.25
./configure --enable-ssl --enable-cgid --enable-rewrite --enable-so
make
make install

echo  "LoadModule ssl_module modules/mod_ssl.so"  >>  /usr/local/apache2/conf/httpd.conf
echo  "LoadModule socache_shmcb_module modules/mod_socache_shmcb.so"  >>  /usr/local/apache2/conf/httpd.conf
echo  "Include conf/extra/httpd-ssl.conf"  >>  /usr/local/apache2/conf/httpd.conf

cd  /usr/local/apache2/conf
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

/usr/local/apache2/bin/httpd  -k  restart


如果要使用 AES256 加密,會要求輸入至少4位數的密碼,而且啟動 httpd 時候也會要求輸入,有些麻煩。

[root@localhost conf]# openssl genrsa -aes256 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.............................................................+++
....................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
139640097662880:error:28069065:lib(40):UI_set_result:result too small:ui_lib.c:869:You must type in 4 to 8191 characters
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
[root@localhost conf]#


[root@localhost conf]# /usr/local/apache2/bin/httpd -k restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
[root@localhost conf]#

(完)

相關

[研究] Apache 2.4.25 (https) + OpenSSL 1.0.1e (yum) 安裝(CentOS 7.3)

[研究] Apache HTTPd Web Server 2.4.6 + HTTPS (SSL) yum 安裝 (CentOS 7.2 x64)
http://shaurong.blogspot.com/2016/08/apache-httpd-web-server-246-https-ssl.html


[研究] [C#] 使用 LibreOffice 5.1.6、5.3.0 SDK 讀取試算表(Calc) 檔案 (.ods)

[研究] [C#] 使用 LibreOffice 5.1.6、5.3.0 SDK 讀取試算表(Calc) 檔案 (.ods)

2016-12-30
2017-03-06更新

先簡單說結論
OpenOffice 4.1.3 SDK  只支援 .NET 2,但不支援 .NET 4.x
LibreOffice 5.3.0 SDK 支援 .NET 4.x,但不支援 x64

程式參考這篇

[研究] [C#] 使用 OpenOffice 4.1.3 SDK 讀取試算表(Calc) 檔案 (.ods)
http://shaurong.blogspot.com/2016/12/c-openoffice-413-sdk-calc-ods.html

編譯出現下面錯誤,似乎需要 .NET 4.x,而非 .NET 2.x

1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3258: 無法解析主要參考 "cli_uretypes, Version=1.0.9.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e, processorArchitecture=MSIL",因為它在 .NET Framework 組件 "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有間接相依性,此組件的版本 "4.0.0.0" 高於目前目標 Framework 中的版本 "2.0.0.0"。

重新建立 .NET 4.0 的方案後測試,出現下面錯誤,疑似需要 x86,而不支援 x64

1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3270: 建置 "MSIL" 之專案的處理器架構與參考 "cli_cppuhelper, Version=1.0.22.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e, processorArchitecture=x86" 的處理器架構 "x86" 不符。這可能會導致執行階段失敗。請考慮透過 [組態管理員] 變更專案的目標處理器架構,使專案與參考之間的處理器架構對應,或者使用符合專案目標處理器架構之處理器架構的參考相依性。

********************************************************************************
2017-03-06 測試 LibreOffice 5.3.0 SDK ,依然不支援 x64 版

1>------ 已開始全部重建: 專案: ODSLibreOffice516Demo, 組態: Debug Any CPU ------
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3270: 建置 "MSIL" 之專案的處理器架構與參考 "cli_cppuhelper, Version=1.0.22.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e, processorArchitecture=x86" 的處理器架構 "x86" 不符。這可能會導致執行階段失敗。請考慮透過 [組態管理員] 變更專案的目標處理器架構,使專案與參考之間的處理器架構對應,或者使用符合專案目標處理器架構之處理器架構的參考相依性。
1>  ODSLibreOffice516Demo -> D:\CodeTemp\ODSLibreOffice530Demo\ODSLibreOffice516Demo\bin\Debug\ODSLibreOffice516Demo.exe
========== 全部重建: 1 成功、0 失敗、 0 略過 ==========


********************************************************************************
(完)

相關

[研究] [C#] 讀取 LibreOffice、OpenOffice 的試算表(Calc) 檔案 (.ods)(使用 .NET 4.5 的 ZipFile)
http://shaurong.blogspot.com/2016/12/c-libreoffice-516-calc-ods-net-45.html

[研究] [C#] 使用 OpenOffice 4.1.3 SDK 讀取試算表(Calc) 檔案 (.ods)

[研究] [C#] 使用 OpenOffice 4.1.3 SDK 讀取試算表(Calc) 檔案 (.ods)

2016-12-30

先簡單說結論
OpenOffice 4.1.3 SDK  只支援 .NET 2,但不支援 .NET 4.x
LibreOffice 5.3.0 SDK 支援 .NET 4.x,但不支援 x64

Apache OpenOffice 4.1.3 SDK 下載
https://www.openoffice.org/download/sdk/

工具:Visual Studio 2015 with Update 3

參考這篇作程式
[研究] [C#] 讀取 LibreOffice、OpenOffice 的試算表(Calc) 檔案 (.ods)(使用 .NET 4.5 的 ZipFile)
http://shaurong.blogspot.com/2016/12/c-libreoffice-516-calc-ods-net-45.html

下載安裝 OpenOffice 4.1.3 SDK
方案的 "參考" 加入 C:\Program Files(x86)\OpenOffice 4\sdk\cli 目錄的
cli_basetypes, cli_cppuhelper, cli_oootypes, cli_ure, and cli_uretypes.dll

其中 WinForm 程式 Form1.cs 片段換成下面


private void button2_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "ods files (*.ods)|*.ods|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        label1.Text = openFileDialog1.FileName; // 包含路徑
                        string inputFilePath = openFileDialog1.FileName; // 包含路徑

                        fileName = openFileDialog1.FileName; // 包含路徑


                        XComponentContext context = Bootstrap.bootstrap();
                        XMultiServiceFactory factory = (XMultiServiceFactory)context.getServiceManager();
                        XComponentLoader loader = (XComponentLoader)factory.createInstance("com.sun.star.frame.Desktop");

                        PropertyValue[] args1 = new PropertyValue[1];
                        args1[0] = new PropertyValue();
                        args1[0].Name = "Hidden";
                        args1[0].Value = new uno.Any((Boolean)true);

                        //XSpreadsheetDocument doc = (XSpreadsheetDocument)loader.loadComponentFromURL("file:///c:/a.ods", "_blank", 0, args1);
                        XSpreadsheetDocument doc = (XSpreadsheetDocument)loader.loadComponentFromURL("file:///" + fileName, "_blank", 0, args1);
                        XSpreadsheets sheets = doc.getSheets();
                        //XSpreadsheet sheet = (XSpreadsheet)sheets.getByName("Sheet1").Value;
                        XSpreadsheet sheet = (XSpreadsheet)sheets.getByName("工作表1").Value;

                        XCell cell = sheet.getCellByPosition(2, 2);
                        label2.Text = cell.ToString();

                        cell.setValue(1000);
                        cell = sheet.getCellByPosition(2, 3);
                        cell.setFormula("Title");

                        XStorable xstorable = (XStorable)doc;
                        PropertyValue[] storeProps = new PropertyValue[1];
                        storeProps[0] = new PropertyValue();
                        storeProps[0].Name = "Overwrite";
                        storeProps[0].Value = new uno.Any((Boolean)true);

                        try
                        {
                            String sURL = "file:///c:/a2.ods";
                            xstorable.storeAsURL(sURL, storeProps);
                            if (doc != null)
                            {
                                XCloseable xCloseable = (XCloseable)doc;
                                xCloseable.close(true);
                                doc = null;
                            }
                        }
                        catch (unoidl.com.sun.star.uno.Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }



                        //DataSet ds = ReadOdsFile(inputFilePath);
                        DataSet ds = ReadOdsFile2(inputFilePath);

                        dataGridView1.AutoGenerateColumns = true;
                        dataGridView1.DataSource = ds; // dataset
                        dataGridView1.DataSource = ds.Tables[0];



                        //using (myStream)
                        //{
                        //    // Insert code to read the stream here.
                        //}
                    }
                }
                catch (unoidl.com.sun.star.uno.Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }

(下圖)執行後發生錯誤,Apache OpenOffice 4.1.3 SDK  疑似支援 .NET 2,但不支援 .NET 4.x


*****

用 .NET 2.0 改寫一次
WinForm 程式 Form1.cs 片段


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

// 下載安裝 OpenOffice 4.1.3 SDK
// "參考" 加入 C:\Program Files(x86)\OpenOffice 4\sdk\cli 目錄的
// cli_basetypes, cli_cppuhelper, cli_oootypes, cli_ure, and cli_uretypes.dll
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.sheet;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.table;
using unoidl.com.sun.star.text;
using uno.util;

using unoidl.com.sun.star.util;
//using unoidl.com.sun.star.sdbc;

namespace ODSOpenOffice413SDKDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string fileName = "";
        private void button1_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "ods files (*.ods)|*.ods|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        label1.Text = openFileDialog1.FileName; // 包含路徑
                        string inputFilePath = openFileDialog1.FileName; // 包含路徑

                        fileName = openFileDialog1.FileName; // 包含路徑

                        //XComponentContext context = Bootstrap.bootstrap();
                        XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
                        XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
                        XComponentLoader loader = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
                        string url = @"private:factory/scalc";
                        PropertyValue[] loadProps = new PropertyValue[1];
                        loadProps[0] = new PropertyValue();
                        loadProps[0].Name = "Hidden";
                        loadProps[0].Value = new uno.Any(true);
                        //PropertyValue[] loadProps = new PropertyValue[0];
                        XComponent document = loader.loadComponentFromURL(url, "_blank", 0, loadProps);

                        PropertyValue[] args1 = new PropertyValue[1];
                        args1[0] = new PropertyValue();
                        args1[0].Name = "Hidden";
                        args1[0].Value = new uno.Any((Boolean)true);

                        //XSpreadsheetDocument doc = (XSpreadsheetDocument)loader.loadComponentFromURL("file:///c:/a.ods", "_blank", 0, args1);
                        XSpreadsheetDocument doc = (XSpreadsheetDocument)loader.loadComponentFromURL("file:///" + fileName, "_blank", 0, args1);

                        XSpreadsheets sheets = doc.getSheets();
                        //XSpreadsheet sheet = (XSpreadsheet)sheets.getByName("Sheet1").Value;
                        XSpreadsheet sheet = (XSpreadsheet)sheets.getByName("工作表1").Value;

                        XCell cell = sheet.getCellByPosition(2, 2);
                        label1.Text = cell.ToString();

                        cell.setValue(1000);
                        cell = sheet.getCellByPosition(2, 3);
                        cell.setFormula("Title");

                        XStorable xstorable = (XStorable)doc;
                        PropertyValue[] storeProps = new PropertyValue[1];
                        storeProps[0] = new PropertyValue();
                        storeProps[0].Name = "Overwrite";
                        storeProps[0].Value = new uno.Any((Boolean)true);

                        try
                        {
                            String sURL = "file:///c:/a2.ods";
                            xstorable.storeAsURL(sURL, storeProps);
                            if (doc != null)
                            {
                                XCloseable xCloseable = (XCloseable)doc;
                                xCloseable.close(true);
                                doc = null;
                            }
                        }
                        catch (unoidl.com.sun.star.uno.Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }



                        //DataSet ds = ReadOdsFile(inputFilePath);
                        //DataSet ds = ReadOdsFile2(inputFilePath);

                        //dataGridView1.AutoGenerateColumns = true;
                        //dataGridView1.DataSource = ds; // dataset
                        //dataGridView1.DataSource = ds.Tables[0];



                        //using (myStream)
                        //{
                        //    // Insert code to read the stream here.
                        //}
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
    }
}


(下圖) 編譯有警告,似乎只支援 x86,不支援 x64
OpenOffice 4.1.3 SDK 安裝目錄為 C:\Program Files(x86)\OpenOffice 4\sdk\   也可知道


(下圖) 實際執行也不行


以下是雜七雜八參考資料
**********

http://jehupc.exblog.jp/12764408/


XComponentContext context = Bootstrap.bootstrap();
XMultiServiceFactory factory = (XMultiServiceFactory)context.getServiceManager();
XComponentLoader loader = (XComponentLoader)factory.createInstance("com.sun.star.frame.Desktop");

PropertyValue[] args1 = new PropertyValue[1];
args1[0] = new PropertyValue();
args1[0].Name = "Hidden";
args1[0].Value = new uno.Any((Boolean)true);

XSpreadsheetDocument doc = (XSpreadsheetDocument)loader.loadComponentFromURL("file:///c:/a.ods", "_blank", 0, args1);
XSpreadsheets sheets = doc.getSheets();
XSpreadsheet sheet = (XSpreadsheet)sheets.getByName("Sheet1").Value;

XCell cell = sheet.getCellByPosition(2, 2);
cell.setValue(1000);
cell = sheet.getCellByPosition(2, 3);
cell.setFormula("Title");

XStorable xstorable = (XStorable)doc;
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "Overwrite";
storeProps[0].Value = new uno.Any((Boolean)true);

try
{
    String sURL = "file:///c:/a2.ods" ;
    xstorable.storeAsURL(sURL, storeProps);
    if (doc != null)
    {
        XCloseable xCloseable = (XCloseable)doc;
        xCloseable.close(true);
        doc = null;
 }
}
catch (unoidl.com.sun.star.uno.Exception ex)
{
    MessageBox.Show(ex.Message);
}


**********

https://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/CLI/Writing_Client_Programs

**********

Use OpenOffice Uno CLI with C# to create a spreadsheet
http://stackoverflow.com/questions/4743738/use-openoffice-uno-cli-with-c-sharp-to-create-a-spreadsheet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.sheet;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.table;
using unoidl.com.sun.star.text;

namespace TimeScanner {
    class ReportGenerator {
        private const string fileName = 
            @"file:///C:/Documents and Settings/My Documents/Hours Report.ods";

        //Concrete Methods
        internal XComponent openCalcSheet() {
            XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
            XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
            XComponentLoader desktop = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
            string url = @"private:factory/scalc";
            PropertyValue[] loadProps = new PropertyValue[1];
            loadProps[0] = new PropertyValue();
            loadProps[0].Name = "Hidden";
            loadProps[0].Value = new uno.Any(true);
            //PropertyValue[] loadProps = new PropertyValue[0];
            XComponent document = desktop.loadComponentFromURL(url, "_blank", 0, loadProps);
            return document;
        }

        public void writeToSheet(XComponent document) {
            XSpreadsheets oSheets = ((XSpreadsheetDocument)document).getSheets();
            XIndexAccess oSheetsIA = (XIndexAccess) oSheets;
            XSpreadsheet sheet = (XSpreadsheet) oSheetsIA.getByIndex(0).Value;
            XCell cell = sheet.getCellByPosition( 0, 0 ); //A1
            ((XText)cell).setString("Cost");
            cell = sheet.getCellByPosition( 1, 0 ); //B1
            cell.setValue(200);
            cell = sheet.getCellByPosition( 1, 2 ); //B3
           cell.setFormula("=B1 * 1.175");
        }

        public void saveCalcSheet(XComponent oDoc) {        
            PropertyValue[] propVals = new PropertyValue[1];
            propVals[0] = new PropertyValue();
            propVals[0].Name = "FilterName";
            propVals[0].Value = new uno.Any("calc8");
            ((XStorable)oDoc).storeToURL(fileName, propVals);
        }
    }
}

Calc/API/Programming
https://wiki.openoffice.org/wiki/Calc/API/Programming
很多範例,但為 C++

How to read ODS Open Office Calc spreadsheet document using Bytescout Spreadsheet for .NET
https://bytescout.com/products/developer/spreadsheetsdk/bytescoutxls_read_ods_open_office_calc_spreadsheet.html

**********

http://www.it1352.com/387358.html


Tutorial for implementing OpenOffice in C++/C#/Java
https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=60522

Read ODS (Open Office Calc) Files
https://s3.amazonaws.com/bytescout.com/files/help/BytescoutSpreadsheetSDK/html/71015e6a-b760-44c5-b53a-0b9c15f7d366.htm
(完)

相關

[研究] [C#] 讀取 LibreOffice、OpenOffice 的試算表(Calc) 檔案 (.ods)(使用 .NET 4.5 的 ZipFile)
http://shaurong.blogspot.com/2016/12/c-libreoffice-516-calc-ods-net-45.html

[研究] OpenOffice 4.1.3 試算表(Calc) 保護鎖定儲存格不被修改

[研究] OpenOffice 4.1.3 試算表(Calc) 保護鎖定儲存格不被修改

2016-12-30

參考

敝人是先選取大範圍的儲存格做鎖定,再選小範圍不做鎖定

(下圖) 選擇要鎖定的範圍

(下圖) 選擇【格式】下拉選單,選擇【儲存格】








(完)

相關

[研究] OpenOffice 4.1.3 試算表(Calc) 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/openoffice-413-calc.html

[研究] LibreOffice 5.1.6 試算表(Calc) 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/libreoffice-516-calc.html

[研究] Excel 2010 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/excel-2010.html

[研究] 使用OpenOffice 4.1.3試算表(Calc)建立「下拉式選單」來輸入資料
http://shaurong.blogspot.com/2016/12/openoffice-413calc.html

[研究] 使用LibreOffice 5.1.6試算表(Calc)建立「下拉式選單」來輸入資料
http://shaurong.blogspot.com/2016/12/libreoffice-516calc.html

[研究] 使用Excel 2010「下拉式選單」來輸入資料
http://shaurong.blogspot.tw/2015/12/excel-2010.html

[研究] LibreOffice 5.1.6 試算表(Calc) 保護鎖定儲存格不被修改

[研究] LibreOffice 5.1.6 試算表(Calc) 保護鎖定儲存格不被修改

2016-12-30

參考

防止儲存格變更
https://help.libreoffice.org/Calc/Protecting_Cells_from_Changes/zh-TW

保護試算表
https://help.libreoffice.org/Calc/Protecting_Sheet/zh-TW

敝人是先選取大範圍的儲存格做鎖定,再選小範圍不做鎖定

(下圖) 選擇要鎖定的範圍


(下圖) 選擇【格式】下拉選單,選擇【儲存】








(下圖) 要變更或解除,再選一次


(完)

相關

[研究] LibreOffice 5.1.6 試算表(Calc) 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/libreoffice-516-calc.html

[研究] Excel 2010 保護鎖定儲存格不被修改
http://shaurong.blogspot.com/2016/12/excel-2010.html

[研究] 使用OpenOffice 4.1.3試算表(Calc)建立「下拉式選單」來輸入資料
http://shaurong.blogspot.com/2016/12/openoffice-413calc.html

[研究] 使用LibreOffice 5.1.6試算表(Calc)建立「下拉式選單」來輸入資料
http://shaurong.blogspot.com/2016/12/libreoffice-516calc.html

[研究] 使用Excel 2010「下拉式選單」來輸入資料
http://shaurong.blogspot.tw/2015/12/excel-2010.html