技術社群

  • twMVC
  • Study4TW
  • 台灣 SQL PASS

技術專家Blog

參考文件

微軟論壇

  • MSDN Forum
  • TechNet Forum

網站分析工具

  • PageRank

最新回應

輸出資料到OpenOffice Scalc

兩種方法(參考 http://www.opendocument4all.com/download/OpenOffice.net.pdf)

1) 透過 OpenOffice 提供的API

須注意安裝的SDK版本不可比安裝的OpenOffice軟體版本新

安裝SDK後,將dll加入參考

SDK 3.0 dll 檔案位於(%InstallPath%/sdk/cli/)

 

using unoidl.com.sun.star.container;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.sheet;
using unoidl.com.sun.star.uno;

XComponentContext localContext = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory) localContext.getServiceManager();
XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
XSpreadsheetDocument workbook = (XSpreadsheetDocument)componentLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new unoidl.com.sun.star.beans.PropertyValue[0]);
XSpreadsheet sheet = getSpreadsheet(workbook,0);
sheet.getCellByPosition(0, 0).setFormula("TEST");

2) Reflection

 

using System.Reflection;

Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
Object oServiceManager = Activator.CreateInstance(tServiceManager);
Object oDesktop = oServiceManager.GetType().InvokeMember("createinstance", BindingFlags.InvokeMethod, null, oServiceManager, new object[] { "com.sun.star.frame.Desktop" });
object oComponent = oDesktop.GetType().InvokeMember("loadComponentFromUrl", BindingFlags.InvokeMethod, null, oDesktop, new object[] { "private:factory/scalc" ,"_blank",0,new Object[] { }});
object sheets = oComponent.GetType().InvokeMember("getSheets", BindingFlags.InvokeMethod, null, oComponent, null);
object sheet = sheets.GetType().InvokeMember( "getByIndex", BindingFlags.InvokeMethod,null,sheets, new object[]{0});
object cell = sheet.GetType().InvokeMember( "getCellByPosition", BindingFlags.InvokeMethod,null,sheet, new object[] { 0, 0 });
cell.GetType().InvokeMember("setFormula", BindingFlags.InvokeMethod,null,cell ,new object[]{"TEST"});

開發環境

VS 2008 C# Express

OpenOffice 3.1

OpenOffice SDK 3.0.0


關連文章

[C#][API]SendInput

手動加入 [繼承的表單]

資料符合特定條件時變更資料列(Row)的背景顏色

[C#][VB.NET]取得印表機資訊

回應

目前沒有回應.

登入後使用進階評論

Please add 7 and 2 and type the answer here: