Exemplo n.º 1
0
        /**
         * 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);
        }
Exemplo n.º 2
0
        /**
         * Handles any addition cell features, such as comments or data
         * validation.  Called internally from this class when a cell is
         * added to the workbook, and also externally from BaseCellFeatures
         * following a call to setComment
         */
        public void addCellFeatures()
        {
            if (features == null)
            {
                return;
            }

            if (copied == true)
            {
                copied = false;

                return;
            }

            if (features.getComment() != null)
            {
                Comment comment = new Comment(features.getComment(),
                                              column, row);
                comment.setWidth(features.getCommentWidth());
                comment.setHeight(features.getCommentHeight());
                sheet.addDrawing(comment);
                sheet.getWorkbook().addDrawing(comment);
                features.setCommentDrawing(comment);
            }

            if (features.hasDataValidation())
            {
                try
                {
                    features.getDVParser().setCell(column,
                                                   row,
                                                   sheet.getWorkbook(),
                                                   sheet.getWorkbook(),
                                                   sheet.getWorkbookSettings());
                }
                catch (CSharpJExcel.Jxl.Biff.Formula.FormulaException e)
                {
                    Assert.verify(false);
                }

                sheet.addValidationCell(this);
                if (!features.hasDropDown())
                {
                    return;
                }

                // Get the combo box drawing object for list validations
                if (sheet.getComboBox() == null)
                {
                    // Need to add the combo box the first time, since even though
                    // it doesn't need a separate Sp entry, it still needs to increment
                    // the shape id
                    ComboBox cb = new ComboBox();
                    sheet.addDrawing(cb);
                    sheet.getWorkbook().addDrawing(cb);
                    sheet.setComboBox(cb);
                }

                features.setComboBox(sheet.getComboBox());
            }
        }