void ConvertWorkSheetData(ISheet sheet, ref WorkSheetData target, DataFormatter df) { var rows = sheet.PhysicalNumberOfRows; var columns = sheet.GetRow(0).PhysicalNumberOfCells; var tab = sheet.SheetName; var data = new string[rows, columns]; var rowHeights = new int[rows]; var columnWidths = new int[columns]; IRow rowData; for (int r = 0; r < rows; r++) { rowData = sheet.GetRow(r); rowHeights[r] = Mathf.CeilToInt(rowData.HeightInPoints + 10); for (int c = 0; c < columns; c++) { data[r, c] = df.FormatCellValue(rowData.GetCell(c)); if (r == 0) { columnWidths[c] = Mathf.CeilToInt(sheet.GetColumnWidthInPixels(c) + 10); } } } target = new WorkSheetData(tab, data, rowHeights, columnWidths); }
public WorkBookData(string path) { XSSFWorkbook workbook; try { using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read)) { workbook = new XSSFWorkbook(stream); } } catch (Exception) { var msg = string.Format("檔案不存在或開啟中.\n{0}", path); Debug.LogError(msg); return; } m_fileName = Path.GetFileNameWithoutExtension(path); var size = workbook.NumberOfSheets; m_WorkSheetTabs = new string[size]; m_WorksheetData = new WorkSheetData[size]; var df = new DataFormatter(CultureInfo.CurrentCulture); ISheet worksheet; for (int i = 0; i < size; i++) { m_WorkSheetTabs[i] = workbook.GetSheetName(i); worksheet = workbook.GetSheetAt(i); ConvertWorkSheetData(worksheet, ref m_WorksheetData[i], df); } }
void SwitchSheet() { sheet = book.GetWorkSheetData(sheetID); var heights = sheet.RowHeights; var widths = sheet.ColumnWidths; var totalHeight = 180; var totalWidth = 80; for (int r = 0; r < heights.Length; r++) { totalHeight += heights[r]; } for (int c = 0; c < widths.Length; c++) { totalWidth += widths[c]; } var minWidth = totalWidth > 1000 ? 1000 : totalWidth; var minHeight = totalHeight > 800 ? 800 : totalHeight; windowMinSize = new Vector2(minWidth, minHeight); windowMaxSize = new Vector2(totalWidth, totalHeight); SwitchWindowSize(); }
public virtual void ConvertSingleWorksheet(WorkSheetData worksheet) { }