예제 #1
0
 public Cell(object value, CellFormat format)
 {
     _value = value;
     _format = format;
 }
예제 #2
0
        internal int GetXFIndex(CellFormat cellFormat)
        {
            string formatKey = cellFormat.ToString();
            if (_cellFormatIndexLookup.ContainsKey(formatKey))
            {
                return _cellFormatIndexLookup[formatKey];
            }

            UInt16 formatIndex = FormatStrings.GetFormatIndex(cellFormat.FormatString.Value);
            if (formatIndex == UInt16.MaxValue)
            {
                formatIndex = _maxNumberFormatIndex++;
            }
            var format = new FORMAT
            {
                FormatIndex = formatIndex,
                FormatString = cellFormat.FormatString.Value
            };
            StringFormatRecords.Add(format);

            ushort fontIndex = Fonts.GetIndex(cellFormat.Font);

            var xf = new XF
            {
                FontIndex = fontIndex,
                FormatIndex = formatIndex,
                Attributes = 252,
                FillPattern = (byte)cellFormat.Pattern.Style,
                PatternColorIndex = cellFormat.Pattern.ForegroundColor.Index,
                PatternBackgroundColorIndex = cellFormat.Pattern.BackgroundColor.Index,
                TopLineStyle = (byte)cellFormat.Border.TopStyle,
                BottomLineStyle = (byte)cellFormat.Border.BottomStyle,
                LeftLineStyle = (byte)cellFormat.Border.LeftStyle,
                RightLineStyle = (byte)cellFormat.Border.RightStyle,
                TopLineColorIndex = cellFormat.Border.TopColor.Index,
                BottomLineColorIndex = cellFormat.Border.BottomColor.Index,
                LeftLineColorIndex = cellFormat.Border.LeftColor.Index,
                RightLineColorIndex = cellFormat.Border.RightColor.Index,
                DiagonalUp = cellFormat.Border.DiagonalUp,
                DiagonalDown = cellFormat.Border.DiagonalDown,
                DiagonalLineStyle = (byte)cellFormat.Border.DiagonalStyle,
                DiagonalLineColorIndex = cellFormat.Border.DiagonalColor.Index,
                CellLocked = cellFormat.LockCell,
                FormulaHidden = cellFormat.HideFormula,
                HorizontalAlign = (byte)cellFormat.TextControl.HorizontalAlignment,
                VerticalAlign = (byte)cellFormat.TextControl.VerticalAlignment,
                TextWrap = cellFormat.TextControl.WrapText,
                JustifyDistributed = cellFormat.TextControl.JustifyDistributed,
                ShrinkContents = cellFormat.TextControl.ShrinkToFit,
                IndentLevel = cellFormat.TextControl.IndentLevel,
                TextDirection = (byte)cellFormat.TextControl.TextDirection
            };
            switch (cellFormat.TextControl.RotationStyle)
            {
                case RotationStyle.CounterClockwise:
                    xf.Rotation = cellFormat.TextControl.TextRotation;
                    break;
                case RotationStyle.Clockwise:
                    xf.Rotation = (byte)(cellFormat.TextControl.TextRotation + 90);
                    break;
                case RotationStyle.Stacked:
                    xf.Rotation = 255;
                    break;
                default:
                    xf.Rotation = 0;
                    break;
            }

            ExtendedFormats.Add(xf);

            _cellFormatIndexLookup.Add(formatKey, ExtendedFormats.Count - 1);

            return ExtendedFormats.Count - 1;
        }
예제 #3
0
 public Cell(object value)
 {
     _value = value;
     _format = CellFormat.General;
 }
예제 #4
0
 public Cell(object value, string formatString)
 {
     _value = value;
     _format = new CellFormat(CellFormatType.General, formatString);
 }
예제 #5
0
        internal int GetXFIndex(CellFormat cellFormat)
        {
            string formatString = cellFormat.FormatString;
            if (NumberFormatXFIndice.ContainsKey(formatString))
            {
                return NumberFormatXFIndice[formatString];
            }
            else
            {
                UInt16 formatIndex = CellFormats.GetFormatIndex(formatString);
                if (formatIndex == UInt16.MaxValue)
                {
                    formatIndex = MaxNumberFormatIndex++;
                }

                FORMAT format = new FORMAT();
                format.FormatIndex = formatIndex;
                format.FormatString = formatString;
                FormatRecords.Add(format);

                XF xf = new XF();
                xf.Attributes = 252;
                xf.CellProtection = 0;
                xf.PatternColorIndex = 64;
                xf.PatternBackgroundColorIndex = 130;
                xf.FontIndex = 0;
                xf.FormatIndex = formatIndex;
                ExtendedFormats.Add(xf);

                int numberFormatXFIndex = ExtendedFormats.Count - 1;
                NumberFormatXFIndice.Add(formatString, numberFormatXFIndex);

                return numberFormatXFIndex;
            }
        }
예제 #6
0
 private CellFormat CreateCellFormatFromXF(XF xf)
 {
     var style = new CellFormat
     {
         FormatString = SharedResource.FormatStrings[xf.FormatIndex],
         //BackgroundColor = SharedResource.ColorPalette[xf.PatternColorIndex]
         // TODO: Read back all this stuff
     };
     return style;
 }
예제 #7
0
 public Cell(object value, CellFormat format)
 {
     _value  = value;
     _format = format;
 }
예제 #8
0
 public Cell(object value)
 {
     _value  = value;
     _format = CellFormat.General;
 }
예제 #9
0
 public Cell(object value, string formatString)
 {
     _value  = value;
     _format = new CellFormat(CellFormatType.General, formatString);
 }
예제 #10
0
 public Cell(object value, CellFormat format)
 {
     this._value  = value;
     this._format = format;
 }
예제 #11
0
 public Cell(object value)
 {
     this._value  = value;
     this._format = CellFormat.General;
 }
예제 #12
0
 public Cell(object value, CellFormat cellFormat)
 {
     _value = value;
     CellFormat = cellFormat;
 }
예제 #13
0
 public Cell(object value, string formatString)
 {
     _value = value;
     CellFormat = new CellFormat {FormatString = {Value = formatString}};
 }
예제 #14
0
 public Cell(object value)
 {
     _value = value;
     CellFormat = new CellFormat();
 }
예제 #15
-11
        static void Main(string[] args)
        {
            var underTest = new Workbook();
            var sheet = new Worksheet("Sheet 1");

            var styleA = new CellFormat();
            styleA.SetBackgroundColor(ExcelColor.Red);
            styleA.Border.DiagonalUp = true;
            styleA.Border.DiagonalDown = true;
            styleA.Border.DiagonalStyle = CellBorderStyle.Thin;
            var styleB = new CellFormat
            {
                Pattern =
                {
                    Style = PatternStyle.LightDown,
                    ForegroundColor = ExcelColor.Blue
                }
            };
            var styleC = new CellFormat();
            styleC.SetBackgroundColor(ExcelColor.Silver);
            styleC.Border = CellBorder.MediumBox;
            styleC.Font.Bold = true;

            for (var i = 0; i < 100; i++)
            {
                var cellA = new Cell("Abcde");
                var cellB = new Cell(1234);
                var cellC = new Cell(string.Format("This is row {0:000}", i));
                if (i%2 == 0)
                {
                    cellA.CellFormat = styleA;
                    cellB.CellFormat = styleB;
                    cellC.CellFormat = styleC;
                }
                else
                {
                    cellB.CellFormat.TextControl.RotationStyle = RotationStyle.CounterClockwise;
                    cellB.CellFormat.TextControl.TextRotation = 45;
                    cellC.VerticalAlignment = VerticalAlignStyle.Centered;
                    cellC.CellFormat.Font.Name = "Times New Roman";
                    cellC.CellFormat.Font.Family = FontFamilyType.Roman;
                    cellC.CellFormat.Font.Height = 240;
                }
                sheet.Cells[i, 0] = cellA;
                sheet.Cells[i, 1] = cellB;
                sheet.Cells[i, 2] = cellC;
                sheet.Cells.ColumnWidth[2] = 256 * 15;
            }
            underTest.Worksheets.Add(sheet);
            var filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "test.xls");
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            underTest.Save(filename);
        }