/** * Create an EventRecordFactory * @param abortable specifies whether the return from the listener * handler functions are obeyed. False means they are ignored. True * means the event loop exits on error. */ public EventRecordFactory(ERFListener listener, ArrayList sids) { _listener = listener; _sids = sids; if (_sids == null) { _sids = null; } else { if (_sids == null) _sids = new ArrayList(); _sids.Sort(); // for faster binary search } }
/** * Create an EventRecordFactory * @param abortable specifies whether the return from the listener * handler functions are obeyed. False means they are ignored. True * means the event loop exits on error. */ public EventRecordFactory(ERFListener listener, ArrayList sids) { _listener = listener; _sids = sids; if (_sids == null) { _sids = null; } else { if (_sids == null) { _sids = new ArrayList(); } _sids.Sort(); // for faster binary search } }
public void TestAddToExistingSheet() { // dvEmpty.xls is a simple one sheet workbook. With a DataValidations header record but no // DataValidations. It's important that the example has one SHEETPROTECTION record. // Such a workbook can be Created in Excel (2007) by Adding datavalidation for one cell // and then deleting the row that Contains the cell. IWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("dvEmpty.xls"); int dvRow = 0; ISheet sheet = wb.GetSheetAt(0); IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper(); IDataValidationConstraint dc = dataValidationHelper.CreateintConstraint(OperatorType.EQUAL, "42", null); IDataValidation dv = dataValidationHelper.CreateValidation(dc, new CellRangeAddressList(dvRow, dvRow, 0, 0)); dv.EmptyCellAllowed = (/*setter*/false); dv.ErrorStyle = (/*setter*/ERRORSTYLE.STOP); dv.ShowPromptBox = (/*setter*/true); dv.CreateErrorBox("Xxx", "Yyy"); dv.SuppressDropDownArrow = (/*setter*/true); sheet.AddValidationData(dv); MemoryStream baos = new MemoryStream(); try { wb.Write(baos); } catch (IOException e) { throw new RuntimeException(e); } byte[] wbData = baos.ToArray(); #if !HIDE_UNREACHABLE_CODE if (false) { // TODO (Jul 2008) fix EventRecordFactory to process unknown records, (and DV records for that matter) ERFListener erfListener = null; // new MyERFListener(); EventRecordFactory erf = new EventRecordFactory(erfListener, null); try { POIFSFileSystem fs = new POIFSFileSystem(new MemoryStream(baos.ToArray())); throw new NotImplementedException("The method CreateDocumentInputStream of POIFSFileSystem is not implemented."); //erf.ProcessRecords(fs.CreateDocumentInputStream("Workbook")); } catch (RecordFormatException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } // else verify record ordering by navigating the raw bytes #endif byte[] dvHeaderRecStart = { (byte)0xB2, 0x01, 0x12, 0x00, }; int dvHeaderOffset = FindIndex(wbData, dvHeaderRecStart); Assert.IsTrue(dvHeaderOffset > 0); int nextRecIndex = dvHeaderOffset + 22; int nextSid = ((wbData[nextRecIndex + 0] << 0) & 0x00FF) + ((wbData[nextRecIndex + 1] << 8) & 0xFF00) ; // nextSid should be for a DVRecord. If anything comes between the DV header record // and the DV records, Excel will not be able to open the workbook without error. if (nextSid == 0x0867) { throw new AssertionException("Identified bug 45519"); } Assert.AreEqual(DVRecord.sid, nextSid); }