/** * Sets the cell features during the reading process * * @param cf the cell features */ public void setCellFeatures(CellFeatures cf) { if (features != null) { //logger.warn("current cell features not null - overwriting"); } features = cf; }
/** * Writes out the data validations */ private void writeDataValidation() { if (dataValidation != null && validatedCells.Count == 0) { // the only data validations are those read in - this should // never be the case now that shared data validations add // to the validatedCells list dataValidation.write(outputFile); return; } if (dataValidation == null && validatedCells.Count > 0) { // the only data validations are those which have been added by the // write API. Need to sort out the combo box id uint comboBoxId = sheet.getComboBox() != null?sheet.getComboBox().getObjectId() : DataValidation.DEFAULT_OBJECT_ID; dataValidation = new DataValidation(comboBoxId, sheet.getWorkbook(), sheet.getWorkbook(), workbookSettings); } foreach (CellValue cv in validatedCells) { CellFeatures cf = cv.getCellFeatures(); // Do not do anything if the DVParser has been copied, as it // will already by on the DataValidation record as a result // of the SheetCopier process if (!cf.getDVParser().copied()) { if (!cf.getDVParser().extendedCellsValidation()) { // DVParser is specific for a single cell validation - just add it DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(cf.getDVParser()); dataValidation.add(dvsr); } else { // Only add the DVParser once for shared validations // only add it if it is the top left cell if (cv.getColumn() == cf.getDVParser().getFirstColumn() && cv.getRow() == cf.getDVParser().getFirstRow()) { DataValiditySettingsRecord dvsr = new DataValiditySettingsRecord(cf.getDVParser()); dataValidation.add(dvsr); } } } } dataValidation.write(outputFile); }
/** * Constructor * * @param w The workbook to interrogate * @param out The output stream to which the CSV values are written * @param encoding The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @exception java.io.IOException */ public Features(Workbook w, TextWriter os, string encoding) { if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } try { //OutputStreamWriter osw = new OutputStreamWriter(out, encoding); //BufferedWriter os = new BufferedWriter(osw); for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++) { Sheet s = w.getSheet(sheet); os.Write(s.getName()); os.WriteLine(); Cell[] row = null; Cell c = null; for (int i = 0; i < s.getRows(); i++) { row = s.getRow(i); for (int j = 0; j < row.Length; j++) { c = row[j]; if (c.getCellFeatures() != null) { CellFeatures features = c.getCellFeatures(); StringBuilder sb = new StringBuilder(); CellReferenceHelper.getCellReference (c.getColumn(), c.getRow(), sb); os.Write("Cell " + sb.ToString() + " contents: " + c.getContents()); os.Flush(); os.Write(" comment: " + features.getComment()); os.Flush(); os.WriteLine(); } } } } os.Flush(); //os.close(); } catch (Exception e) { Console.WriteLine(e); } }
/** * Sets the cell features * * @param cf the cell features */ public void setCellFeatures(CellFeatures cf) { features = cf; }
/** * Copy constructor * * @param cf the cell to copy */ public WritableCellFeatures(CellFeatures cf) : base(cf) { }
/** * Adds a cell comment to a cell just read in * * @param col1 the column for the comment * @param row1 the row for the comment * @param col2 the row for the comment * @param row2 the row for the comment * @param dvsr the validation settings */ private void addCellValidation(int col1,int row1,int col2,int row2,DataValiditySettingsRecord dvsr) { for (int row = row1; row <= row2; row++) { for (int col = col1; col <= col2; col++) { Cell c = null; if (cells.GetLength(0) > row && cells.GetLength(1) > col) c = cells[row,col]; if (c == null) { MulBlankCell mbc = new MulBlankCell(row, col, 0, formattingRecords, sheet); CellFeatures cf = new CellFeatures(); cf.setValidationSettings(dvsr); mbc.setCellFeatures(cf); addCell(mbc); } else if (c is CellFeaturesAccessor) { // Check to see if the cell already contains a comment CellFeaturesAccessor cv = (CellFeaturesAccessor)c; CellFeatures cf = cv.getCellFeatures(); if (cf == null) { cf = new CellFeatures(); cv.setCellFeatures(cf); } cf.setValidationSettings(dvsr); } else { //logger.warn("Not able to add comment to cell type " + c.GetType().Name + // " at " + CellReferenceHelper.getCellReference(col, row)); } } } }
/** * Adds a cell comment to a cell just read in * * @param col the column for the comment * @param row the row for the comment * @param text the comment text * @param width the width of the comment text box * @param height the height of the comment text box */ private void addCellComment(int col,int row,string text,double width,double height) { Cell c = cells[row,col]; if (c == null) { //logger.warn("Cell at " + CellReferenceHelper.getCellReference(col, row) + // " not present - adding a blank"); MulBlankCell mbc = new MulBlankCell(row, col, 0, formattingRecords, sheet); CellFeatures cf = new CellFeatures(); cf.setReadComment(text, width, height); mbc.setCellFeatures(cf); addCell(mbc); return; } if (c is CellFeaturesAccessor) { CellFeaturesAccessor cv = (CellFeaturesAccessor)c; CellFeatures cf = cv.getCellFeatures(); if (cf == null) { cf = new CellFeatures(); cv.setCellFeatures(cf); } cf.setReadComment(text, width, height); } else { //logger.warn("Not able to add comment to cell type " + c.GetType().Name + // " at " + CellReferenceHelper.getCellReference(col, row)); } }