/** * Constructs this object from the raw data * * @param num the numerical representation of this * @param xfi the java equivalent of the excel date format * @param fr the formatting records * @param nf flag indicating whether we are using the 1904 date system * @param si the sheet */ public DateRecord(NumberCell num, int xfi, FormattingRecords fr, bool nf, SheetImpl si) { row = num.getRow(); column = num.getColumn(); xfIndex = xfi; formattingRecords = fr; sheet = si; initialized = false; format = formattingRecords.getDateFormat(xfIndex); // This value represents the number of days since 01 Jan 1900 double numValue = num.getValue(); if (Math.Abs(numValue) < 1) { if (format == null) { format = timeFormat; } time = true; } else { if (format == null) { format = dateFormat; } time = false; } // Work round a bug in excel. Excel seems to think there is a date // called the 29th Feb, 1900 - but in actual fact this was not a leap year. // Therefore for values less than 61 in the 1900 date system, // add one to the numeric value if (!nf && !time && numValue < nonLeapDay) { numValue += 1; } // Get rid of any timezone adjustments - we are not interested // in automatic adjustments // TODO: CML -- don't know what to do here.... // format.setTimeZone(gmtZone); // Convert this to the number of days since 01 Jan 1970 int offsetDays = nf ? utcOffsetDays1904 : utcOffsetDays; double utcDays = numValue - offsetDays; // Convert this into utc by multiplying by the number of milliseconds // in a day. Use the round function prior to ms conversion due // to a rounding feature of Excel (contributed by Jurgen) long utcValue = (long)Math.Round(utcDays * secondsInADay) * msInASecond; date = new System.DateTime(ticksTo1970 + (utcValue * msTicks)); }
/// <summary> /// Adds a RK Biffrecord to the internal list /// additional the method adds the specific RK Data to a data container /// </summary> /// <param name="number">NUMBER Biffrecord</param> public void addRK(RK singlerk) { this.SINGLERKList.Add(singlerk); RowData rowData = this.getSpecificRow(singlerk.rw); NumberCell cell = new NumberCell(); cell.setValue(singlerk.num); cell.Col = singlerk.col; cell.Row = singlerk.rw; cell.TemplateID = singlerk.ixfe; rowData.addCell(cell); }
/// <summary> /// Adds a NUMBER Biffrecord to the internal list /// additional the method adds the specific NUMBER Data to a data container /// </summary> /// <param name="number">NUMBER Biffrecord</param> public void addNUMBER(Number number) { this.NUMBERList.Add(number); RowData rowData = this.getSpecificRow(number.rw); NumberCell cell = new NumberCell(); cell.setValue(number.num); cell.Col = number.col; cell.Row = number.rw; cell.TemplateID = number.ixfe; rowData.addCell(cell); }
/// <summary> /// Adds a mulrk record element to the internal list /// a mulrk record stores some integer or floatingpoint values /// </summary> /// <param name="mulrk">The MULRK Record</param> public void addMULRK(MulRk mulrk) { this.MULRKList.Add(mulrk); RowData rowData = this.getSpecificRow(mulrk.rw); if (mulrk.ixfe.Count == mulrk.rknumber.Count) { for (int i = 0; i < mulrk.rknumber.Count; i++) { NumberCell cell = new NumberCell(); cell.Col = mulrk.colFirst + i; cell.Row = mulrk.rw; cell.setValue(mulrk.rknumber[i]); cell.TemplateID = mulrk.ixfe[i]; rowData.addCell(cell); } } }
/** * Constructs this object from the raw data * * @param num the numerical representation of this * @param xfi the java equivalent of the excel date format * @param fr the formatting records * @param nf flag indicating whether we are using the 1904 date system * @param si the sheet */ public DateRecord(NumberCell num, int xfi,FormattingRecords fr, bool nf,SheetImpl si) { row = num.getRow(); column = num.getColumn(); xfIndex = xfi; formattingRecords = fr; sheet = si; initialized = false; format = formattingRecords.getDateFormat(xfIndex); // This value represents the number of days since 01 Jan 1900 double numValue = num.getValue(); if (Math.Abs(numValue) < 1) { if (format == null) format = timeFormat; time = true; } else { if (format == null) format = dateFormat; time = false; } // Work round a bug in excel. Excel seems to think there is a date // called the 29th Feb, 1900 - but in actual fact this was not a leap year. // Therefore for values less than 61 in the 1900 date system, // add one to the numeric value if (!nf && !time && numValue < nonLeapDay) { numValue += 1; } // Get rid of any timezone adjustments - we are not interested // in automatic adjustments // TODO: CML -- don't know what to do here.... // format.setTimeZone(gmtZone); // Convert this to the number of days since 01 Jan 1970 int offsetDays = nf ? utcOffsetDays1904 : utcOffsetDays; double utcDays = numValue - offsetDays; // Convert this into utc by multiplying by the number of milliseconds // in a day. Use the round function prior to ms conversion due // to a rounding feature of Excel (contributed by Jurgen) long utcValue = (long)Math.Round(utcDays * secondsInADay) * msInASecond; date = new System.DateTime(ticksTo1970 + (utcValue * msTicks)); }
private NumberCell(NumberCell cell) { value = cell.value; }
/// <summary> Constructs this object from the raw data /// /// </summary> /// <param name="num">the numerical representation of this /// </param> /// <param name="xfi">the java equivalent of the excel date format /// </param> /// <param name="fr"> the formatting records /// </param> /// <param name="nf"> flag indicating whether we are using the 1904 date system /// </param> /// <param name="si"> the sheet /// </param> public DateRecord(NumberCell num, int xfi, FormattingRecords fr, bool nf, SheetImpl si) { row = num.Row; column = num.Column; xfIndex = xfi; formattingRecords = fr; sheet = si; initialized = false; format = formattingRecords.getDateFormat(xfIndex); // This value represents the number of days since 01 Jan 1900 double numValue = num.DoubleValue; // Work round a bug in excel. Excel seems to think there is a date // called the 29th Feb, 1900 - but in actual fact this was not a leap year. // Therefore for values less than 61 in the 1900 date system, // add one to the numeric value if (!nf && numValue < nonLeapDay) { numValue += 1; } if (System.Math.Abs(numValue) < 1) { if (format == null) { format = timeFormat; } time = true; } else { if (format == null) { format = dateFormat; } time = false; } // Get rid of any timezone adjustments - we are not interested // in automatic adjustments // [TODO-NExcel_Next] // format.setTimeZone(gmtZone); // Convert this to the number of days since 01 Jan 1970 int offsetDays = nf?utcOffsetDays1904:utcOffsetDays; double utcDays = numValue - offsetDays; // Convert this into utc by multiplying by the number of milliseconds // in a day // long utcValue = (long) System.Math.Round(utcDays * msInADay); // convert it to 100 nanoseconds long utcValue = (long)System.Math.Round(utcDays * msInADay * 10000); // add the reference date (1/1/1970) DateTime refdate = new DateTime(1970, 1, 1); utcValue += refdate.Ticks; _Value = new DateTime(utcValue); }
/** * Constructor used when copying a workbook * * @param nc the number to copy */ protected NumberRecord(NumberCell nc) : base(Type.NUMBER, nc) { value = nc.getValue(); }
private SheetData CreateSheetData <T>(List <T> objects, List <string> headerNames, WorkbookStylesPart stylesPart) { SheetData sheetData = new SheetData(); if (objects != null) { //Fields names of object List <string> fields = GetPropertyInfo <T>(); var az = new List <Char>(Enumerable.Range('A', 'Z' - 'A' + 1).Select(i => (Char)i).ToArray()); List <Char> headers = az.GetRange(0, fields.Count); int numRows = objects.Count; int numCols = fields.Count; Row header = new Row(); int index = 1; header.RowIndex = (uint)index; for (int col = 0; col < numCols; col++) { //Cell c = CreateHeaderCell(headers[col].ToString(), headerNames[col], index, stylesPart.Stylesheet); HeaderCell c = new HeaderCell(headers[col].ToString(), headerNames[col], index, stylesPart.Stylesheet, System.Drawing.Color.DodgerBlue, 12, true); header.Append(c); } sheetData.Append(header); CultureInfo ci = new CultureInfo("en-US"); for (int i = 0; i < numRows; i++) { index++; var obj1 = objects[i]; var r = new Row { RowIndex = (uint)index }; for (int col = 0; col < numCols; col++) { string fieldName = fields[col]; PropertyInfo myf = obj1.GetType().GetProperty(fieldName); if (myf != null) { object obj = myf.GetValue(obj1, null); if (obj != null) { if (obj.GetType() == typeof(string)) { // Cell c = CreateTextCell(headers[col].ToString(), obj.ToString(), index); TextCell c = new TextCell(headers[col].ToString(), obj.ToString(), index); r.Append(c); } else if (obj.GetType() == typeof(bool)) { string value = (bool)obj ? "Yes" : "No"; //Cell c = CreateTextCell(headers[col].ToString(), value, index); TextCell c = new TextCell(headers[col].ToString(), value, index); r.Append(c); } else if (obj.GetType() == typeof(DateTime)) { //string value = GetExcelSerialDate((DateTime) obj).ToString(); string value = ((DateTime)obj).ToOADate().ToString(ci); // stylesPart.Stylesheet is retrieved reference for the appropriate worksheet. //Cell c = CreateDateCell(headers[col].ToString(), value, index, stylesPart.Stylesheet); DateCell c = new DateCell(headers[col].ToString(), (DateTime)obj, index); r.Append(c); } else if (obj.GetType() == typeof(decimal)) { //Cell c = CreateDecimalCell(headers[col].ToString(), obj.ToString(), index, stylesPart.Stylesheet); FormatedNumberCell c = new FormatedNumberCell(headers[col].ToString(), ((decimal)obj).ToString(ci), index); r.Append(c); } else if (obj.GetType() == typeof(double)) { //Cell c = CreateDecimalCell(headers[col].ToString(), obj.ToString(), index, stylesPart.Stylesheet); FormatedNumberCell c = new FormatedNumberCell(headers[col].ToString(), ((double)obj).ToString(ci), index); r.Append(c); } else { long value; if (long.TryParse(obj.ToString(), out value)) { //Cell c = CreateIntegerCell(headers[col].ToString(), obj.ToString(), index); NumberCell c = new NumberCell(headers[col].ToString(), value.ToString(ci), index); r.Append(c); } else { //Cell c = CreateTextCell(headers[col].ToString(), obj.ToString(), index); TextCell c = new TextCell(headers[col].ToString(), obj.ToString(), index); r.Append(c); } } } } } sheetData.Append(r); } } return(sheetData); }
/** * Constructor used internally by the application when making a writable * copy of a spreadsheet that has been read in * * @param nc the cell to copy */ public Number(NumberCell nc) : base(nc) { }