private float GetColumnWidthInPixels(int columnIndex) { XSSFSheet sheet = (XSSFSheet)GetDrawing().GetParent(); CT_Col col = sheet.GetColumnHelper().GetColumn(columnIndex, false); double numChars = col == null || !col.IsSetWidth() ? DEFAULT_COLUMN_WIDTH : col.width; return((float)numChars * XSSFWorkbook.DEFAULT_CHARACTER_WIDTH); }
public RenderExcel2007(Report rep, IStreamGen sg) { report = rep; _sg = sg; // We need this in future excelBuilder.Report = report; styles = new List <XSSFCellStyle>(); fonts = new List <XSSFFont>(); worksheet = (XSSFSheet)workbook.CreateSheet(string.IsNullOrEmpty(rep.Name) ? "NewSheet" : rep.Name); var ps = (XSSFPrintSetup)worksheet.PrintSetup; ps.SetPaperSize(PaperSize.A4); ps.Orientation = PrintOrientation.LANDSCAPE; worksheet.SetMargin(MarginType.LeftMargin, rep.LeftMarginPoints / 72); worksheet.SetMargin(MarginType.TopMargin, rep.TopMarginPoints / 72); worksheet.SetMargin(MarginType.RightMargin, rep.RightMarginPoints / 72); worksheet.SetMargin(MarginType.BottomMargin, rep.BottomMarginPoints / 72); columnHelper = worksheet.GetColumnHelper(); }
public void TestGetOrCreateColumn() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet 1"); ColumnHelper columnHelper = sheet.GetColumnHelper(); // Check POI 0 based, OOXML 1 based CT_Col col = columnHelper.GetOrCreateColumn1Based(3, false); Assert.IsNotNull(col); Assert.IsNull(columnHelper.GetColumn(1, false)); Assert.IsNotNull(columnHelper.GetColumn(2, false)); Assert.IsNotNull(columnHelper.GetColumn1Based(3, false)); Assert.IsNull(columnHelper.GetColumn(3, false)); CT_Col col2 = columnHelper.GetOrCreateColumn1Based(30, false); Assert.IsNotNull(col2); Assert.IsNull(columnHelper.GetColumn(28, false)); Assert.IsNotNull(columnHelper.GetColumn(29, false)); Assert.IsNotNull(columnHelper.GetColumn1Based(30, false)); Assert.IsNull(columnHelper.GetColumn(30, false)); }
public void TestGetSetColDefaultStyle() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet(); CT_Worksheet ctWorksheet = sheet.GetCTWorksheet(); ColumnHelper columnHelper = sheet.GetColumnHelper(); // POI column 3, OOXML column 4 CT_Col col = columnHelper.GetOrCreateColumn1Based(4, false); Assert.IsNotNull(col); Assert.IsNotNull(columnHelper.GetColumn(3, false)); columnHelper.SetColDefaultStyle(3, 2); Assert.AreEqual(2, columnHelper.GetColDefaultStyle(3)); Assert.AreEqual(-1, columnHelper.GetColDefaultStyle(4)); StylesTable stylesTable = workbook.GetStylesSource(); CT_Xf cellXf = new CT_Xf(); cellXf.fontId = (0); cellXf.fillId = (0); cellXf.borderId = (0); cellXf.numFmtId = (0); cellXf.xfId = (0); stylesTable.PutCellXf(cellXf); CT_Col col_2 = ctWorksheet.GetColsArray(0).AddNewCol(); col_2.min = (10); col_2.max = (12); col_2.style = (1); col_2.styleSpecified = true; Assert.AreEqual(1, columnHelper.GetColDefaultStyle(11)); XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null); columnHelper.SetColDefaultStyle(11, cellStyle); Assert.AreEqual(0u, col_2.style); Assert.AreEqual(1, columnHelper.GetColDefaultStyle(10)); }