public void TestCTTableStyleInfo() { XSSFWorkbook outputWorkbook = new XSSFWorkbook(); XSSFSheet sheet = outputWorkbook.CreateSheet() as XSSFSheet; //Create XSSFTable outputTable = sheet.CreateTable(); outputTable.DisplayName = ("Test"); CT_Table outputCTTable = outputTable.GetCTTable(); //Style configurations CT_TableStyleInfo outputStyleInfo = outputCTTable.AddNewTableStyleInfo(); outputStyleInfo.name = ("TableStyleLight1"); outputStyleInfo.showColumnStripes = (false); outputStyleInfo.showRowStripes = (true); XSSFWorkbook inputWorkbook = XSSFTestDataSamples.WriteOutAndReadBack(outputWorkbook) as XSSFWorkbook; List <XSSFTable> tables = (inputWorkbook.GetSheetAt(0) as XSSFSheet).GetTables(); Assert.AreEqual(1, tables.Count, "Tables number"); XSSFTable inputTable = tables[0]; Assert.AreEqual(outputTable.DisplayName, inputTable.DisplayName, "Table display name"); CT_TableStyleInfo inputStyleInfo = inputTable.GetCTTable().tableStyleInfo; Assert.AreEqual(outputStyleInfo.name, inputStyleInfo.name, "Style name"); Assert.AreEqual(outputStyleInfo.showColumnStripes, inputStyleInfo.showColumnStripes, "Show column stripes"); Assert.AreEqual(outputStyleInfo.showRowStripes, inputStyleInfo.showRowStripes, "Show row stripes"); }
public void Bug56274() { // read sample file XSSFWorkbook inputWorkbook = XSSFTestDataSamples.OpenSampleWorkbook("56274.xlsx"); // read the original sheet header order XSSFRow row = inputWorkbook.GetSheetAt(0).GetRow(0) as XSSFRow; List <String> headers = new List <String>(); foreach (ICell cell in row) { headers.Add(cell.StringCellValue); } // no SXSSF class // save the worksheet as-is using SXSSF //File outputFile = File.CreateTempFile("poi-56274", ".xlsx"); //SXSSFWorkbook outputWorkbook = new NPOI.XSSF.streaming.SXSSFWorkbook(inputWorkbook); //outputWorkbook.Write(new FileOutputStream(outputFile)); // re-read the saved file and make sure headers in the xml are in the original order //inputWorkbook = new NPOI.XSSF.UserModel.XSSFWorkbook(new FileStream(outputFile)); inputWorkbook = XSSFTestDataSamples.WriteOutAndReadBack(inputWorkbook) as XSSFWorkbook; CT_Table ctTable = (inputWorkbook.GetSheetAt(0) as XSSFSheet).GetTables()[0].GetCTTable(); List <CT_TableColumn> ctTableColumnList = ctTable.tableColumns.tableColumn; Assert.AreEqual(headers.Count, ctTableColumnList.Count, "number of headers in xml table should match number of header cells in worksheet"); for (int i = 0; i < headers.Count; i++) { Assert.AreEqual(headers[i], ctTableColumnList[i].name, "header name in xml table should match number of header cells in worksheet"); } //Assert.IsTrue(outputFile.Delete()); }
private void AddColumn(CT_Table table, uint index) { var column = new CT_TableColumn(); column.name = "Column" + index; column.id = index + 1; table.tableColumns.tableColumn.Add(column); }
public void ReadFrom(Stream is1) { try { this.ctTable = TableDocument.Parse(is1).GetTable(); } catch (XmlException ex) { throw new IOException(ex.Message); } }
public void ReadFrom(Stream is1) { try { TableDocument doc = TableDocument.Parse(is1); ctTable = doc.GetTable(); } catch (XmlException e) { throw new IOException(e.Message); } }
public void ReadFrom(XmlDocument xmlDoc) { try { TableDocument doc = TableDocument.Parse(xmlDoc, NamespaceManager); ctTable = doc.GetTable(); } catch (XmlException e) { throw new IOException(e.Message); } }
public void GetRowCount() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.CreateSheet() as XSSFSheet; XSSFTable table = sh.CreateTable() as XSSFTable; CT_Table ctTable = table.GetCTTable(); Assert.AreEqual(0, table.RowCount); ctTable.@ref = "B2:B2"; // update cell references to clear the cache table.UpdateReferences(); Assert.AreEqual(1, table.RowCount); ctTable.@ref = "B2:B12"; // update cell references to clear the cache table.UpdateReferences(); Assert.AreEqual(11, table.RowCount); }
public void GetCellReferences() { // make sure that cached start and end cell references // can be synchronized with the underlying CTTable XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.CreateSheet() as XSSFSheet; XSSFTable table = sh.CreateTable() as XSSFTable; CT_Table ctTable = table.GetCTTable(); ctTable.@ref = "B2:E8"; Assert.AreEqual(new CellReference("B2"), table.StartCellReference); Assert.AreEqual(new CellReference("E8"), table.EndCellReference); // At this point start and end cell reference are cached // and may not follow changes to the underlying CTTable ctTable.@ref = "C1:M3"; Assert.AreEqual(new CellReference("B2"), table.StartCellReference); Assert.AreEqual(new CellReference("E8"), table.EndCellReference); // Force a synchronization between CTTable and XSSFTable // start and end cell references table.UpdateReferences(); Assert.AreEqual(new CellReference("C1"), table.StartCellReference); Assert.AreEqual(new CellReference("M3"), table.EndCellReference); }
public XSSFTable() : base() { ctTable = new CT_Table(); }
public static void WriteDMToTable(this ISheet sheet, List <DefineSelectItem> lst, string tableName, int numCol) { if (lst == null || lst.Count == 0) { return; } XSSFSheet s = (XSSFSheet)sheet; XSSFTable tbl = s.GetTables().Where(a => a.Name == tableName).FirstOrDefault(); if (tbl == null) { return; } CT_Table ctTBl = tbl.GetCTTable(); if (numCol < 2 || ctTBl.tableColumns.count < numCol) { return; } CellReference cellRefStart = tbl.GetStartCellReference(); int rowStart = cellRefStart.Row + 1; short colStart = cellRefStart.Col; CellReference cellRefEnd = tbl.GetEndCellReference(); AreaReference reference = new AreaReference(cellRefStart, new CellReference(cellRefStart.Row + lst.Count, cellRefEnd.Col)); ctTBl.insertRow = true; ctTBl.insertRowShift = true; ctTBl.@ref = reference.FormatAsString(); IRow row = GetCreateRow(sheet, rowStart); switch (numCol) { case 3: foreach (DefineSelectItem item in lst) { row = GetCreateRow(sheet, rowStart++); row.GetCreateCell(colStart).SetCellValue(item.Value); row.GetCreateCell(colStart + 1).SetCellValue(item.Value2); row.GetCreateCell(colStart + 2).SetCellValue(item.Text); } break; case 4: foreach (DefineSelectItem item in lst) { row = GetCreateRow(sheet, rowStart++); row.GetCreateCell(colStart).SetCellValue(item.Value); row.GetCreateCell(colStart + 1).SetCellValue(item.Value2); row.GetCreateCell(colStart + 2).SetCellValue(item.Value3); row.GetCreateCell(colStart + 3).SetCellValue(item.Text); } break; case 2: default: foreach (DefineSelectItem item in lst) { row = GetCreateRow(sheet, rowStart++); row.GetCreateCell(colStart).SetCellValue(item.Value); row.GetCreateCell(colStart + 1).SetCellValue(item.Text); } break; } }
public XSSFTable() { this.ctTable = new CT_Table(); }