public Worksheet(Workbook owner, XSpreadsheet xsheet) { this.Workbook = owner; this.Peer = xsheet; }
//シートの洗濯 public void SelectSheet(string sheetName) { // sheetを取得 "Spec" sheet = (XSpreadsheet)sheets.getByName(sheetName).Value; }
public static void ExportExcelLO(string FileName, DataSet ds) { try { string unoPath = @"C:\Program Files (x86)\LibreOffice 5\program"; Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process); 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[3]; loadProps[0] = new PropertyValue() { Name = "Hidden", Value = new uno.Any(true) }; loadProps[1] = new PropertyValue() { Name = "FilterName", Value = new uno.Any("MS Excel 97") }; loadProps[2] = new PropertyValue() { Name = "ReadOnly", Value = new uno.Any(false) }; XComponent document = desktop.loadComponentFromURL(url, "_blank", 0, loadProps); XSpreadsheets oSheets = ((XSpreadsheetDocument)document).getSheets(); XIndexAccess oSheetsIA = (XIndexAccess)oSheets; XSpreadsheet sheet = (XSpreadsheet)oSheetsIA.getByIndex(0).Value; int ii = 0; XCell celija = null; foreach (DataColumn kol in ds.Tables[0].Columns) { celija = sheet.getCellByPosition(ii, 0); ((XText)celija).setString(kol.ColumnName); //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(654321)); //((XPropertySet)celija).setPropertyValue("CharColor", new uno.Any(333444)); ii++; } ds.Tables[0].AcceptChanges(); ii = 0; foreach (DataRow red in ds.Tables[0].Rows) { int jj = 0; ii++; foreach (object ob in red.ItemArray) { celija = sheet.getCellByPosition(jj, ii); ((XText)celija).setString(ob.ToString()); //((XPropertySet)celija).setPropertyValue("CellBackColor", new uno.Any(888777)); jj++; } } ((XStorable)document).storeToURL("file:///" + FileName.Replace(@"\", "/"), loadProps); System.Diagnostics.Process.Start(FileName); } catch (System.Exception ex) { throw ex; } }