private static void setValue(NPOI.SS.UserModel.ISheet sheet, int rowIndex, int colIndex, double value) { IRow row = sheet.GetRow(rowIndex); if (row == null) { row = sheet.CreateRow(rowIndex); } row.CreateCell(colIndex).SetCellValue(value); }
/// <summary> /// Gets the row height in points. /// </summary> /// <param name="sheet">The sheet.</param> /// <param name="rowNum">The row num.</param> /// <returns></returns> private float GetRowHeightInPoints(NPOI.SS.UserModel.ISheet sheet, int rowNum) { NPOI.SS.UserModel.IRow row = sheet.GetRow(rowNum); if (row == null) return sheet.DefaultRowHeightInPoints; else return row.HeightInPoints; }
private void ActivateSheet(NPOI.SS.UserModel.Sheet sheet) { DataTable dt = new DataTable(sheet.SheetName); int maxCx = 0; int cy = sheet.PhysicalNumberOfRows; for (int y = 0; y < cy; y++) { NPOI.SS.UserModel.Row row = sheet.GetRow(y); if (row != null) { int cx = row.PhysicalNumberOfCells; maxCx = Math.Max(maxCx, row.FirstCellNum + cx); } } int maxCy = sheet.FirstRowNum + cy; for (int x = 0; x < maxCx; x++) { DataColumn col = dt.Columns.Add("C" + (1 + x), typeof(String)); } for (int vy = 0; vy < maxCy; vy++) { DataRow dr = dt.NewRow(); if (vy >= sheet.FirstRowNum) { int y = vy - sheet.FirstRowNum; NPOI.SS.UserModel.Row row = sheet.GetRow(y); for (int vx = 0; vx < maxCx; vx++) { dr[vx] = ""; if (row != null) { if (vx >= row.FirstCellNum) { int x = vx - row.FirstCellNum; NPOI.SS.UserModel.Cell cell = row.GetCell(x); dr[vx] = (cell != null) ? cell.ToString() : ""; } } } } dt.Rows.Add(dr); } gv.DataSource = dt; foreach (DataGridViewColumn col in gv.Columns) { col.ReadOnly = true; } gv.AutoResizeColumns(); gv.AutoResizeRows(); }
private static String GetFormulaFromFirstCell(NPOI.SS.UserModel.ISheet s, int rowIx) { return s.GetRow(rowIx).GetCell((short)0).CellFormula; }
private static void ConfirmEmptyRow(NPOI.SS.UserModel.ISheet s, int rowIx) { IRow row = s.GetRow(rowIx); Assert.IsTrue(row == null || row.PhysicalNumberOfCells == 0); }
private static void ConfirmCell(NPOI.SS.UserModel.ISheet sheet, int rowIx, int colIx, double expectedValue, String expectedFormula) { ICell cell = sheet.GetRow(rowIx).GetCell(colIx); Assert.AreEqual(expectedValue, cell.NumericCellValue, 0.0); Assert.AreEqual(expectedFormula, cell.CellFormula); }