Exemplo n.º 1
0
        Range GetRange(int r1, int c1, int r2, int c2)
        {
            string cell1 = ExcelSupport.GetCellSymbol(r1, c1);
            string cell2 = ExcelSupport.GetCellSymbol(r2, c2);

            return(_sheet.get_Range(cell1, cell2));
        }
Exemplo n.º 2
0
        void insertFormatData(ExcelFormatData formatData)
        {
            foreach (ExcelRangeInfo range in formatData.Ranges)
            {
                Range rng = GetRange(range);


                try
                {
                    if (formatData.Foreground.HasValue)
                    {
                        rng.Font.Color = ColorTranslator.ToOle(formatData.Foreground.Value);
                    }

                    if (formatData.Background.HasValue)
                    {
                        rng.Interior.Color = ColorTranslator.ToOle(formatData.Background.Value);
                    }

                    if (formatData.FontSize.HasValue)
                    {
                        rng.Font.Size = formatData.FontSize.Value;
                    }

                    if (formatData.IsFontBold.HasValue)
                    {
                        rng.Font.Bold = formatData.IsFontBold.Value;
                    }

                    if (formatData.IsFontItalic.HasValue)
                    {
                        rng.Font.Italic = formatData.IsFontItalic.Value;
                    }

                    if (formatData.IsWrapped.HasValue)
                    {
                        rng.WrapText = formatData.IsWrapped.Value;
                    }

                    if (formatData.IsCoumnAutofit.HasValue)
                    {
                        foreach (Range col in rng.Columns)
                        {
                            col.EntireColumn.AutoFit();
                        }
                    }

                    if (formatData.HorizontalAlignment.HasValue)
                    {
                        XlHAlign horizAlignment = (XlHAlign)formatData.HorizontalAlignment.Value;
                        rng.HorizontalAlignment = horizAlignment;
                    }

                    if (formatData.Vertical.HasValue)
                    {
                        XlVAlign verticalAlignment = (XlVAlign)formatData.Vertical.Value;
                        rng.VerticalAlignment = verticalAlignment;
                    }

                    if (formatData.IsPrintArea.HasValue && formatData.IsPrintArea.Value)
                    {
                        _sheet.PageSetup.PrintArea = rng.Address;
                        _sheet.DisplayPageBreaks   = true;
                    }

                    if (formatData.ColumnWidths != null)
                    {
                        for (int c = 0; c < formatData.ColumnWidths.Length; ++c)
                        {
                            int col = range.Start.Column + c;

                            string colSymbol = ExcelSupport.GetColumnSymbol(col);

                            string colRange = string.Format("{0}:{1}", colSymbol, colSymbol);

                            int width = formatData.ColumnWidths[c];
                            _sheet.get_Range(colRange).EntireColumn.ColumnWidth = width;
                        }
                    }
                }
                catch (Exception exc)
                {
                }
            }
        }
Exemplo n.º 3
0
        Range GetCell(int r, int c)
        {
            string cell = ExcelSupport.GetCellSymbol(r, c);

            return(_sheet.get_Range(cell, cell));
        }