**********
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