Monday, 15 August 2011

Friday, 8 July 2011

How to read and write Word/Excel 2007 files from C# programs?

(1) Add following references to your VS2008 project:
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;

full spec of above packages can be found at:
Microsoft.Office.Interop.Word Namespace
Microsoft.Office.Interop.Excel Namespace

Alternatively, you can use the 'object browser' from VS2008 or F1 key online help

(2) create following object in your C# programs and work on them:
object oMissing = System.Reflection.Missing.Value;
Excel.Application oXL = new Excel.Application();
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks._Open("my_workbook.xlsx", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing));
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Sheets["my_sheet"];
Excel.Range oRng = oSheet.UsedRange;

Word._Application oWord = new Word.Application();
Word._Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;
oDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;
oDoc.PageSetup.LeftMargin = oWord.MillimetersToPoints(15F);
oDoc.PageSetup.RightMargin = oWord.MillimetersToPoints(15F);
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Table oTable = oDoc.Tables.Add(wrdRng, 1, num_of_cols, ref oMissing, ref oMissing);

(3) clean the objects afterward:
object oDoNotSave = Word.WdSaveOptions.wdDoNotSaveChanges;
oDoc.Close(ref oDoNotSave, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
oWB.Close(oMissing, oMissing, oMissing);
oXL.Quit();

Thursday, 2 June 2011

如何开发JRuby+MySQL+Rails 3程序?

安装JDK 1.6
--------------------------
下载jdk-6u25-linux-x64.bin
chmod 700 jdk-6u25-linux-x64.bin
./jdk-6u25-linux-x64.bin

安装JRuby
--------------------------
下载jruby-bin-1.6.2.tar.gz
tar xvfz jruby-bin-1.6.2.tar.gz

安装GlassFish
-------------------------
下载glassfish-3.1.1-ml.zip
unzip glassfish-3.1.1-ml.zip

在.bash_profile中添加设置如下:
--------------------------
JAVA_HOME=$HOME/jdk1.6.0_25
JRUBY_HOME=$HOME/jruby-1.6.2
GLASSFISH_HOME=$HOME/glassfish3
PATH=$JAVA_HOME/bin:$JRUBY_HOME/bin:$GLASSFISH_HOME/bin:$PATH:$HOME/bin
export PATH JAVA_HOME JRUBY_HOME

重新登录

安装rails, jdbcmysql, glassfish gem, warbler
--------------------------
gem install rails activerecord-jdbcmysql-adapter glassfish warbler

创建MySQL用户
--------------------------
mysql -u root -p
mysql> create user duke@localhost identified by 'glassfish';
mysql> grant all on hello_development.* to duke@localhost;
mysql> grant all on hello_production.* to duke@localhost;
mysql> flush privileges;

创建hello程序
--------------------------
rails new hello -m http://jruby.org/rails3.rb -d mysql
cd hello
修改 config/database.yml中的MySQL用户名及口令


创建development数据库
-------------------------
rake db:create
rake db:migrate

创建production数据库
-------------------------
rake db:create RAILS_ENV='production'
rake db:migrate RAILS_ENV='production'

启动WEBrick (使用development数据库)
-------------------------
rails s
检查http://localhost:3000/是否正常

启动Glassfish gem(使用production数据库)
-------------------------
确认在/etc/hosts中,127.0.0.1映射到你的机器名(用hostname命令查看)
在 hello/Gemfile中添加gem 'glassfish'
(it is ok with development database)
glassfish hello
(there is a Routing Error: No route matches "/" with production database)
glassfish hello -e production

启动GlassFish(使用development数据库)
-------------------------
asadmin create-domain --portbase 2000 --domaindir . mydomain
asadmin start-domain --domaindir . mydomain

cd hello
warble
将hello.war放置到Glassfish上

Friday, 13 May 2011

如何测试FTPS?

启动RIP Linux

联网:dhcpup -u

配置:在/etc/lftp.conf里加上

set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no

测试:
lftp -u '<username>,<password>' -d <server_ip>
ls
put file1
get file2
quit

Tuesday, 3 May 2011

如何用Slax提取Windows虚拟机里的文件?

(1) 用Slax光盘"Slax Copy To RAM"模式启动Windows虚拟机

(2)从光驱中移去Slax光盘

(3)为虚拟机安装VBoxAdditions


(4)为虚拟机添加共享文件夹q5

(5)连接共享文件夹
mkdir /mnt/q5
mount -t vboxsf q5 /mnt/q5

(6)拷贝所需文件至/mnt/q5
注:硬盘分区接点一般为/mnt/hda1,/mnt/hda2等等

Monday, 28 March 2011