public FormatInfo(CellInfo cell) { this.cell = cell; if (string.IsNullOrEmpty(cell.Format)) formatIndex = 0; else formatIndex = cell.Document.Formats.IndexOf(cell.Format); FontInfo fontInfo = new FontInfo(cell.Font, cell.ForeColor); fontIndex = cell.Document.Fonts.IndexOf(fontInfo); if (fontIndex == -1) { cell.Document.Fonts.Add(fontInfo); fontIndex = cell.Document.Fonts.IndexOf(fontInfo); } if (fontIndex > 3) fontIndex++; }
internal Cell(int row, int column, ExcelDocument document) { this.document = document; cellInfo = document.GetCellInfo(row, column); }
private void WriteStringCell(BinaryWriter writer, CellInfo cell) { string value; if (cell.Value is string) value = (string)cell.Value; else value = cell.Value.ToString(); if (value.Length > 255) value = value.Substring(0, 255); ushort[] clData = { BIFF.LabelRecord, 0, 0, 0, 0, 0 }; byte[] plainText = Encoding.GetEncoding(CodePage).GetBytes(value); int iLen = plainText.Length; clData[1] = (ushort)(8 + iLen); clData[2] = (ushort)cell.Row; clData[3] = (ushort)cell.Column; clData[4] = (ushort)cell.FXIndex; clData[5] = (ushort)iLen; WriteUshortArray(writer, clData); writer.Write(plainText); }
private void WriteNumberCell(BinaryWriter writer, CellInfo cell) { double dValue = Convert.ToDouble(cell.Value); ushort[] clData = { BIFF.NumberRecord, 14, (ushort)cell.Row, (ushort)cell.Column, (ushort)cell.FXIndex }; WriteUshortArray(writer, clData); writer.Write(dValue); }
private void WriteEmptyCell(BinaryWriter writer, CellInfo cell) { ushort[] clData = { 0x0201, 6, 0, 0, 15 }; clData[2] = (ushort)cell.Row; clData[3] = (ushort)cell.Column; WriteUshortArray(writer, clData); }
private void WriteDateCell(BinaryWriter writer, CellInfo cell) { DateTime value; if (cell.Value is DateTime) { value = (DateTime)cell.Value; DateTime baseDate = new DateTime(1899, 12, 31); TimeSpan ts = value - baseDate; double days = (double)(ts.Days + 1); if (days >= 60) { days += 1; } ushort[] clData = { BIFF.NumberRecord, 14, (ushort)cell.Row, (ushort)cell.Column, (ushort)cell.FXIndex }; WriteUshortArray(writer, clData); writer.Write(days); } }
private void WriteCellValue(BinaryWriter writer, CellInfo cell) { if (cell.Value == null) WriteEmptyCell(writer, cell); else if (cell.Value is string) WriteStringCell(writer, cell); else if (IsNumber(cell.Value)) WriteNumberCell(writer, cell); else if (cell.Value is DateTime) WriteDateCell(writer, cell); else WriteStringCell(writer, cell); }
internal CellInfo GetCellInfo(int row, int column) { Int64 key = HashCode(row, column); CellInfo result; if (cells.TryGetValue(key, out result)) return result; else { if (rows.IndexOf(row) == -1) rows.Add(row); result = new CellInfo(this); result.Row = row; result.Column = column; cells.Add(key, result); return result; } }