public void TestOnARealFile() { HSSFWorkbook workbook = HSSFTestDataSamples.OpenSampleWorkbook("DateFormats.xls"); NPOI.SS.UserModel.Sheet sheet = workbook.GetSheetAt(0); NPOI.HSSF.Model.Workbook wb = workbook.Workbook; Row row; Cell cell; NPOI.SS.UserModel.CellStyle style; double aug_10_2007 = 39304.0; // Should have dates in 2nd column // All of them are the 10th of August // 2 US dates, 3 UK dates row = sheet.GetRow(0); cell = row.GetCell(1); style = cell.CellStyle; Assert.AreEqual(aug_10_2007, cell.NumericCellValue, 0.0001); Assert.AreEqual("d-mmm-yy", style.GetDataFormatString()); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsInternalDateFormat(style.DataFormat)); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsADateFormat(style.DataFormat, style.GetDataFormatString())); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsCellDateFormatted(cell)); row = sheet.GetRow(1); cell = row.GetCell(1); style = cell.CellStyle; Assert.AreEqual(aug_10_2007, cell.NumericCellValue, 0.0001); Assert.IsFalse(NPOI.SS.UserModel.DateUtil.IsInternalDateFormat(cell.CellStyle.DataFormat)); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsADateFormat(style.DataFormat, style.GetDataFormatString())); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsCellDateFormatted(cell)); row = sheet.GetRow(2); cell = row.GetCell(1); style = cell.CellStyle; Assert.AreEqual(aug_10_2007, cell.NumericCellValue, 0.0001); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsInternalDateFormat(cell.CellStyle.DataFormat)); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsADateFormat(style.DataFormat, style.GetDataFormatString())); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsCellDateFormatted(cell)); row = sheet.GetRow(3); cell = row.GetCell(1); style = cell.CellStyle; Assert.AreEqual(aug_10_2007, cell.NumericCellValue, 0.0001); Assert.IsFalse(NPOI.SS.UserModel.DateUtil.IsInternalDateFormat(cell.CellStyle.DataFormat)); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsADateFormat(style.DataFormat, style.GetDataFormatString())); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsCellDateFormatted(cell)); row = sheet.GetRow(4); cell = row.GetCell(1); style = cell.CellStyle; Assert.AreEqual(aug_10_2007, cell.NumericCellValue, 0.0001); Assert.IsFalse(NPOI.SS.UserModel.DateUtil.IsInternalDateFormat(cell.CellStyle.DataFormat)); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsADateFormat(style.DataFormat, style.GetDataFormatString())); Assert.IsTrue(NPOI.SS.UserModel.DateUtil.IsCellDateFormatted(cell)); }
public void TestBackupRecord() { HSSFWorkbook wb = new HSSFWorkbook(); wb.CreateSheet(); NPOI.HSSF.Model.Workbook workbook = wb.Workbook; BackupRecord record = workbook.BackupRecord; Assert.AreEqual(0, record.Backup); wb.BackupFlag = (true); Assert.AreEqual(1, record.Backup); }
public HSSFWorkbook(Workbook book) : base(null, null) { workbook = book; _sheets = new ArrayList(INITIAL_CAPACITY); names = new ArrayList(INITIAL_CAPACITY); }
/// <summary> /// given a POI POIFSFileSystem object, and a specific directory /// within it, Read in its Workbook and populate the high and /// low level models. If you're Reading in a workbook...start here. /// </summary> /// <param name="directory">the POI filesystem directory to Process from</param> /// <param name="fs">the POI filesystem that Contains the Workbook stream.</param> /// <param name="preserveNodes">whether to preseve other nodes, such as /// macros. This takes more memory, so only say yes if you /// need to. If Set, will store all of the POIFSFileSystem /// in memory</param> public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, bool preserveNodes) : base(directory, fs) { String workbookName = GetWorkbookDirEntryName(directory); this.preserveNodes = preserveNodes; // If we're not preserving nodes, don't track the // POIFS any more if (!preserveNodes) { this.filesystem = null; this.directory = null; } _sheets = new ArrayList(INITIAL_CAPACITY); names = new ArrayList(INITIAL_CAPACITY); // Grab the data from the workbook stream, however // it happens to be spelled. Stream stream = directory.CreatePOIFSDocumentReader(workbookName); IList records = RecordFactory.CreateRecords(stream); workbook = Workbook.CreateWorkbook(records); SetPropertiesFromWorkbook(workbook); int recOffset = workbook.NumRecords; // Convert all LabelRecord records to LabelSSTRecord ConvertLabelRecords(records, recOffset); RecordStream rs = new RecordStream(records, recOffset); while (rs.HasNext()) { Sheet sheet = Sheet.CreateSheet(rs); _sheets.Add(new HSSFSheet(this, sheet)); } for (int i = 0; i < workbook.NumNames; ++i) { HSSFName name = new HSSFName(this, workbook.GetNameRecord(i)); names.Add(name); } }
/// <summary> /// Initializes a new instance of the <see cref="HSSFRichTextString"/> class. /// </summary> /// <param name="book">The workbook.</param> /// <param name="record">The record.</param> public HSSFRichTextString(Workbook book, LabelSSTRecord record) { SetWorkbookReferences(book, record); this.str = book.GetSSTString(record.SSTIndex); }
/// <summary> /// This must be called to Setup the internal work book references whenever /// a RichTextString Is Added to a cell /// </summary> /// <param name="book">The workbook.</param> /// <param name="record">The record.</param> public void SetWorkbookReferences(Workbook book, LabelSSTRecord record) { this.book = book; this.record = record; }
/** * Read support for low level * API. Pass in an array of Record objects, A Workbook * object is constructed and passed back with all of its initialization Set * to the passed in records and references to those records held. Unlike Sheet * workbook does not use an offset (its assumed to be 0) since its first in a file. * If you need an offset then construct a new array with a 0 offset or Write your * own ;-p. * * @param recs an array of Record objects * @return Workbook object */ public static Workbook CreateWorkbook(List<Record> recs) { //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "Workbook (Readfile) Created with reclen=", // recs.Count); Workbook retval = new Workbook(); List<Record> records = new List<Record>(recs.Count / 3); retval.records.Records=records; int k; for (k = 0; k < recs.Count; k++) { Record rec = (Record)recs[k]; if (rec.Sid == EOFRecord.sid) { records.Add(rec); //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found workbook eof record at " + k); break; } switch (rec.Sid) { case BoundSheetRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found boundsheet record at " + k); retval.boundsheets.Add((BoundSheetRecord)rec); retval.records.Bspos=k; break; case SSTRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found sst record at " + k); retval.sst = (SSTRecord)rec; break; case FontRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found font record at " + k); retval.records.Fontpos=k; retval.numfonts++; break; case ExtendedFormatRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found XF record at " + k); retval.records.Xfpos=k; retval.numxfs++; break; case TabIdRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found tabid record at " + k); retval.records.Tabpos=k; break; case ProtectRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found protect record at " + k); retval.records.Protpos=k; break; case BackupRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found backup record at " + k); retval.records.Backuppos=k; break; case ExternSheetRecord.sid: throw new Exception("Extern sheet is part of LinkTable"); case NameRecord.sid: case SupBookRecord.sid: // LinkTable can start with either of these //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found SupBook record at " + k); retval.linkTable = new LinkTable(recs, k, retval.records); k += retval.linkTable.RecordCount -1; continue; case FormatRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found format record at " + k); retval.formats.Add((FormatRecord)rec); retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).GetIndexCode() ? retval.maxformatid : ((FormatRecord)rec).GetIndexCode(); break; case DateWindow1904Record.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found datewindow1904 record at " + k); retval.uses1904datewindowing = ((DateWindow1904Record)rec).Windowing == 1; break; case PaletteRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found palette record at " + k); retval.records.Palettepos=k; break; case WindowOneRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found WindowOneRecord at " + k); retval.windowOne = (WindowOneRecord)rec; break; case WriteAccessRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found WriteAccess at " + k); retval.writeAccess = (WriteAccessRecord)rec; break; case WriteProtectRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found WriteProtect at " + k); retval.writeProtect = (WriteProtectRecord)rec; break; case FileSharingRecord.sid: //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "found FileSharing at " + k); retval.fileShare = (FileSharingRecord)rec; break; } records.Add(rec); } //What if we dont have any ranges and supbooks // if (retval.records.supbookpos == 0) { // retval.records.supbookpos = retval.records.bspos + 1; // retval.records.namepos = retval.records.supbookpos + 1; // } // Look for other interesting values that // follow the EOFRecord for (; k < recs.Count; k++) { Record rec = (Record)recs[k]; switch (rec.Sid) { case HyperlinkRecord.sid: retval.hyperlinks.Add((HyperlinkRecord)rec); break; } } if (retval.windowOne == null) { retval.windowOne = (WindowOneRecord)retval.CreateWindowOne(); } //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "exit Create workbook from existing file function"); return retval; }
/** * Creates an empty workbook object with three blank sheets and all the empty * fields. Use this to Create a workbook from scratch. */ public static Workbook CreateWorkbook() { //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "creating new workbook from scratch"); Workbook retval = new Workbook(); List<Record> records = new List<Record>(30); retval.records.Records=records; List<FormatRecord> formats = new List<FormatRecord>(8); records.Add(retval.CreateBOF()); records.Add(retval.CreateInterfaceHdr()); records.Add(retval.CreateMMS()); records.Add(retval.CreateInterfaceEnd()); records.Add(retval.CreateWriteAccess()); records.Add(retval.CreateCodepage()); records.Add(retval.CreateDSF()); records.Add(retval.CreateTabId()); retval.records.Tabpos=records.Count - 1; records.Add(retval.CreateFnGroupCount()); records.Add(retval.CreateWindowProtect()); records.Add(retval.CreateProtect()); retval.records.Protpos=records.Count - 1; records.Add(retval.CreatePassword()); records.Add(retval.CreateProtectionRev4()); records.Add(retval.CreatePasswordRev4()); retval.windowOne = (WindowOneRecord)retval.CreateWindowOne(); records.Add(retval.windowOne); records.Add(retval.CreateBackup()); retval.records.Backuppos=records.Count - 1; records.Add(retval.CreateHideObj()); records.Add(retval.CreateDateWindow1904()); records.Add(retval.CreatePrecision()); records.Add(retval.CreateRefreshAll()); records.Add(retval.CreateBookBool()); records.Add(retval.CreateFont()); records.Add(retval.CreateFont()); records.Add(retval.CreateFont()); records.Add(retval.CreateFont()); retval.records.Fontpos=records.Count - 1; // last font record postion retval.numfonts = 4; // Set up format records for (int i = 0; i <= 7; i++) { Record rec; rec = retval.CreateFormat(i); retval.maxformatid = retval.maxformatid >= ((FormatRecord)rec).GetIndexCode() ? retval.maxformatid : ((FormatRecord)rec).GetIndexCode(); formats.Add((FormatRecord)rec); records.Add(rec); } retval.formats = formats; for (int k = 0; k < 21; k++) { records.Add(retval.CreateExtendedFormat(k)); retval.numxfs++; } retval.records.Xfpos=records.Count - 1; for (int k = 0; k < 6; k++) { records.Add(retval.CreateStyle(k)); } records.Add(retval.CreateUseSelFS()); int nBoundSheets = 1; // now just do 1 for (int k = 0; k < nBoundSheets; k++) { BoundSheetRecord bsr = (BoundSheetRecord)retval.CreateBoundSheet(k); records.Add(bsr); retval.boundsheets.Add(bsr); retval.records.Bspos=records.Count - 1; } // retval.records.supbookpos = retval.records.bspos + 1; // retval.records.namepos = retval.records.supbookpos + 2; records.Add(retval.CreateCountry()); for (int k = 0; k < nBoundSheets; k++) { retval.OrCreateLinkTable.CheckExternSheet(k); } retval.sst = (SSTRecord)retval.CreateSST(); records.Add(retval.sst); records.Add(retval.CreateExtendedSST()); records.Add(retval.CreateEOF()); //if (log.Check(POILogger.DEBUG)) // log.Log(DEBUG, "exit Create new workbook from scratch"); return retval; }
/// <summary> /// Initializes a new instance of the <see cref="HSSFCellStyle"/> class. /// </summary> /// <param name="index">The index.</param> /// <param name="rec">The record.</param> /// <param name="workbook">The workbook.</param> public HSSFCellStyle(short index, ExtendedFormatRecord rec, NPOI.HSSF.Model.Workbook workbook) { this.workbook = workbook; this.index = index; format = rec; }
/// <summary> /// Wraps up your stub Workbook as a stub /// HSSFWorkbook, ready for passing to /// HSSFFormulaParser /// </summary> /// <param name="workbook">The stub workbook.</param> /// <returns></returns> public static HSSFWorkbook CreateStubHSSFWorkbook(Workbook workbook) { return new StubHSSFWorkbook(workbook); }
public HSSFWorkbook(Workbook book) : base(null, null) { workbook = book; _sheets = new List<HSSFSheet>(INITIAL_CAPACITY); names = new List<HSSFName>(INITIAL_CAPACITY); }
public StubHSSFWorkbook(Workbook wb) : base(wb) { }
/// <summary> /// Creates new HSSFSheet - called by HSSFWorkbook to Create a sheet from /// scratch. You should not be calling this from application code (its protected anyhow). /// </summary> /// <param name="workbook">The HSSF Workbook object associated with the sheet..</param> /// <see cref="NPOI.HSSF.UserModel.HSSFWorkbook.CreateSheet"/> public HSSFSheet(HSSFWorkbook workbook) { sheet = Sheet.CreateSheet(); rows = new Dictionary<int,HSSFRow>(); this.workbook = workbook; this.book = workbook.Workbook; }
/// <summary> /// Creates an HSSFSheet representing the given Sheet object. Should only be /// called by HSSFWorkbook when Reading in an exisiting file. /// </summary> /// <param name="workbook">The HSSF Workbook object associated with the sheet.</param> /// <param name="sheet">lowlevel Sheet object this sheet will represent</param> /// <see cref="NPOI.HSSF.UserModel.HSSFWorkbook.CreateSheet"/> public HSSFSheet(HSSFWorkbook workbook, Sheet sheet) { this.sheet = sheet; rows = new Dictionary<int,HSSFRow>(); this.workbook = workbook; this.book = workbook.Workbook; SetPropertiesFromSheet(sheet); }
/** * used internally to Set the workbook properties. */ private void SetPropertiesFromWorkbook(Workbook book) { this.workbook = book; // none currently }
//private static POILogger log = POILogFactory.GetLogger(typeof(HSSFSheet)); /// <summary> /// Creates new HSSFSheet - called by HSSFWorkbook to Create a _sheet from /// scratch. You should not be calling this from application code (its protected anyhow). /// </summary> /// <param name="_workbook">The HSSF Workbook object associated with the _sheet..</param> /// <see cref="NPOI.HSSF.UserModel.HSSFWorkbook.CreateSheet"/> public HSSFSheet(HSSFWorkbook _workbook) { _sheet = Sheet.CreateSheet(); rows = new Dictionary<int, NPOI.SS.UserModel.Row>(); this._workbook = _workbook; this.book = _workbook.Workbook; }
private bool movedBuiltins = false; // Flag to see if need to // Check the built in list // or if the regular list // has all entries. /// <summary> /// Construncts a new data formatter. It takes a workbook to have /// access to the workbooks format records. /// </summary> /// <param name="workbook">the workbook the formats are tied to..</param> public HSSFDataFormat(Workbook workbook) { this.workbook = workbook; IEnumerator i = workbook.Formats.GetEnumerator(); while (i.MoveNext()) { FormatRecord r = (FormatRecord)i.Current; for (int j = formats.Count; formats.Count <= r.GetIndexCode(); j++) { formats.Add(null); } formats[r.GetIndexCode()] = r.GetFormatString(); } }
/// <summary> /// Get the contents of the format string, by looking up /// the DataFormat against the supplied workbook /// </summary> /// <param name="workbook">The workbook.</param> /// <returns></returns> public String GetDataFormatString(NPOI.HSSF.Model.Workbook workbook) { HSSFDataFormat format = new HSSFDataFormat(workbook); return(format.GetFormat(DataFormat)); }
private HSSFEvaluationWorkbook(HSSFWorkbook book) { _uBook = book; _iBook = book.Workbook; }
/// <summary> /// Creates an HSSFSheet representing the given Sheet object. Should only be /// called by HSSFWorkbook when Reading in an exisiting file. /// </summary> /// <param name="_workbook">The HSSF Workbook object associated with the _sheet.</param> /// <param name="_sheet">lowlevel Sheet object this _sheet will represent</param> /// <see cref="NPOI.HSSF.UserModel.HSSFWorkbook.CreateSheet"/> public HSSFSheet(HSSFWorkbook workbook, Sheet sheet) { this._sheet = sheet; rows = new Dictionary<int, NPOI.SS.UserModel.Row>(); this._workbook = workbook; this.book = _workbook.Workbook; SetPropertiesFromSheet(_sheet); }