Пример #1
0
        public override TFlxPartialFormat Evaluate(ExcelFile workbook, TXlsCellRange rangeToFormat, object[] parameters)
        {
            //Again, this example is not supposed to make sense, only to show how you can code a complex rule.
            //This method will format the rows with a color that depends in the length of the first parameter,
            //and if the second parameter starts with "B" it will make the text red.

            if (parameters == null || parameters.Length != 2)
            {
                throw new ArgumentException("Bad parameter count in call to ShipFormat() user-defined format");
            }

            int    len     = Convert.ToString(parameters[0]).Length;
            string country = Convert.ToString(parameters[1]);

            Int32      color = 0xFFFFFF - len * 100;
            TFlxFormat fmt   = workbook.GetDefaultFormat;

            fmt.FillPattern.Pattern = TFlxPatternStyle.Solid;
            fmt.FillPattern.FgColor = TExcelColor.FromArgb(color);
            fmt.FillPattern.BgColor = TExcelColor.Automatic;

            TFlxApplyFormat apply = new TFlxApplyFormat();

            apply.FillPattern.SetAllMembers(true);

            if (country.StartsWith("B"))
            {
                fmt.Font.Color   = Colors.OrangeRed;
                apply.Font.Color = true;
            }

            return(new TFlxPartialFormat(fmt, apply, false));
        }
Пример #2
0
        public override TFlxPartialFormat Evaluate(ExcelFile workbook, TXlsCellRange rangeToFormat, object[] parameters)
        {
            if (parameters == null || parameters.Length != 1)
            {
                throw new ArgumentException("Bad parameter count in call to ZipCode() user-defined format");
            }

            int color;

            //If the zip code is not valid, don't modify the format.
            if (parameters[0] == null || !int.TryParse(Convert.ToString(parameters[0]), out color))
            {
                return(new TFlxPartialFormat(null, null, false));
            }

            //This code is not supposed to make sense. We will convert the zip code to a color based in the numeric value.
            TFlxFormat fmt = workbook.GetDefaultFormat;

            fmt.FillPattern.Pattern = TFlxPatternStyle.Solid;
            fmt.FillPattern.FgColor = TExcelColor.FromArgb(color);
            fmt.FillPattern.BgColor = TExcelColor.Automatic;

            fmt.Font.Color = TExcelColor.FromArgb(~color);

            TFlxApplyFormat apply = new TFlxApplyFormat();

            apply.FillPattern.SetAllMembers(true);
            apply.Font.Color = true;
            return(new TFlxPartialFormat(fmt, apply, false));
        }
        public ExtendedXlsFile(TExportExcelAdapterType ExportType, int sheetCount = 1) : base(true)
        {
            this.CurrentExportType = ExportType;
            //this.ListFormulsByID = new Dictionary<Guid, SortedList>();
            listDataSummary = new List <DataForSummary>();

            NewFile(sheetCount);
            TFlxFormat getDefaultFormat = GetDefaultFormat;
            int        defaultFormatId  = DefaultFormatId;

            //getDefaultFormat.Font.Size20 -= FontOffset;
            SetFormat(defaultFormatId, getDefaultFormat);
            PrintOptions &= ~(TPrintOptions.NoPls | TPrintOptions.Orientation);
            PrintScale    = 100;
            PrintNumberOfHorizontalPages = 1;
            PrintNumberOfVerticalPages   = 20;
            SetPrintMargins(new TXlsMargins(0.2, 0.2, 0.2, 0.2, 0.2, 0.2));

            if (ExportType == TExportExcelAdapterType.toHTML)
            {
                getDefaultFormat.FillPattern.Pattern = TFlxPatternStyle.Solid;
                getDefaultFormat.FillPattern.FgColor = Color.FromArgb(140, 0xc0, 0xe9);
                SetFormat(defaultFormatId, getDefaultFormat);
            }
        }
Пример #4
0
        private void AddData(ExcelFile Xls)
        {
            //Create a new file. We could also open an existing file with Xls.Open
            Xls.NewFile(1, TExcelFileFormat.v2019);
            //Set some cell values.
            Xls.SetCellValue(1, 1, "Hello to the world");
            Xls.SetCellValue(2, 1, 3);
            Xls.SetCellValue(3, 1, 2.1);
            Xls.SetCellValue(4, 1, new TFormula("=Sum(A2,A3)"));

            //Load an image from disk.
            string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (Image Img = Image.FromFile(AssemblyPath + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "Test.bmp"))
            {
                //Add a new image on cell E2
                Xls.AddImage(2, 6, Img);
                //Add a new image with custom properties at cell F6
                Xls.AddImage(Img, new TImageProperties(new TClientAnchor(TFlxAnchorType.DontMoveAndDontResize, 2, 10, 6, 10, 100, 100, Xls), ""));
                //Swap the order of the images. it is not really necessary here, we could have loaded them on the inverse order.
                Xls.BringToFront(1);
            }

            //Add a comment on cell a2
            Xls.SetComment(2, 1, "This is 3");

            //Custom Format cells a2 and a3
            TFlxFormat f = Xls.GetDefaultFormat;

            f.Font.Name           = "Times New Roman";
            f.Font.Color          = Color.Red;
            f.FillPattern.Pattern = TFlxPatternStyle.LightDown;
            f.FillPattern.FgColor = Color.Blue;
            f.FillPattern.BgColor = Color.White;

            //You can call AddFormat as many times as you want, it will never add a format twice.
            //But if you know the format you are going to use, you can get some extra CPU cycles by
            //calling addformat once and saving the result into a variable.
            int XF = Xls.AddFormat(f);

            Xls.SetCellFormat(2, 1, XF);
            Xls.SetCellFormat(3, 1, XF);

            f.Rotation            = 45;
            f.FillPattern.Pattern = TFlxPatternStyle.Solid;
            int XF2 = Xls.AddFormat(f);

            //Apply a custom format to all the row.
            Xls.SetRowFormat(1, XF2);

            //Merge cells
            Xls.MergeCells(5, 1, 10, 6);
            //Note how this one merges with the previous range, creating a final range (5,1,15,6)
            Xls.MergeCells(10, 6, 15, 6);


            //Make the page print in landscape or portrait mode
            Xls.PrintLandscape = false;
        }
        private int SetCellFontStyle(int Row, int Col, TFlxFormat Fx)
        {
            int cellFormat = GetCellFormat(Row, Col);

            cellFormat = AddFormat(Fx);
            SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
Пример #6
0
 internal void SetFormat(int aRow, int aCol, TFlxFormat Fmt)
 {
     if (!Includes(aRow, aCol))
     {
         return;
     }
     Formats[aRow - FirstRow, aCol - FirstCol] = Fmt;
 }
        public int SetCellFontColor(int Row, int Col, Color fc)
        {
            int        cellFormat = GetCellFormat(Row, Col);
            TFlxFormat format     = GetFormat(cellFormat);

            format.Font.Color = fc;
            cellFormat        = AddFormat(format);
            SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
        public int SetCellAlignH(int Row, int Col, THFlxAlignment Ha)
        {
            int        cellFormat = this.GetCellFormat(Row, Col);
            TFlxFormat format     = this.GetFormat(cellFormat);

            format.HAlignment = Ha;
            cellFormat        = this.AddFormat(format);
            this.SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
        public int SetCellAlignV(int Row, int Col, TVFlxAlignment Va)
        {
            int        cellFormat = this.GetCellFormat(Row, Col);
            TFlxFormat format     = this.GetFormat(cellFormat);

            format.VAlignment = Va;
            cellFormat        = this.AddFormat(format);
            this.SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
        public int SetCellFontStyle(int Row, int Col, TFlxFontStyles fs)
        {
            int        cellFormat = this.GetCellFormat(Row, Col);
            TFlxFormat format     = this.GetFormat(cellFormat);

            format.Font.Style = fs;
            cellFormat        = this.AddFormat(format);
            this.SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
Пример #11
0
        internal int SetCellWrapText(int row, int col, bool Wrap)
        {
            int        ff = GetCellFormat(row, col);
            TFlxFormat FX = GetFormat(ff);

            FX.WrapText = Wrap;
            ff          = AddFormat(FX);
            SetCellFormat(row, col, ff);
            return(ff);
        }
Пример #12
0
    private void CreateFile(ExcelFile Xls)
    {
        //Create a new file. We could also open an existing file with Xls.Open
        Xls.NewFile(1, TExcelFileFormat.v2019);
        //Set some cell values.
        Xls.SetCellValue(1, 1, "Hello to everybody");
        Xls.SetCellValue(2, 1, 3);
        Xls.SetCellValue(3, 1, 2.1);
        Xls.SetCellValue(4, 1, new TFormula("=Sum(A2,A3)"));

        //Load an image from disk.
        string AssemblyPath = HttpContext.Current.Request.PhysicalApplicationPath;

        using (System.Drawing.Image Img = System.Drawing.Image.FromFile(Path.Combine(Path.Combine(AssemblyPath, "images"), "Test.bmp")))
        {
            //Add a new image on cell E5
            Xls.AddImage(2, 6, Img);
            //Add a new image with custom properties at cell F6
            Xls.AddImage(Img, new TImageProperties(new TClientAnchor(TFlxAnchorType.DontMoveAndDontResize, 2, 10, 6, 10, 100, 100, Xls), ""));
            //Swap the order of the images. it is not really necessary here, we could have loaded them on the inverse order.
            Xls.BringToFront(1);
        }

        //Add a comment on cell a2
        Xls.SetComment(2, 1, "This is 3");

        //Custom Format cells a2 and a3
        TFlxFormat f = Xls.GetDefaultFormat;

        f.Font.Name           = "Times New Roman";
        f.Font.Color          = Color.Red;
        f.FillPattern.Pattern = TFlxPatternStyle.LightDown;
        f.FillPattern.FgColor = Color.Blue;
        f.FillPattern.BgColor = Color.White;

        int XF = Xls.AddFormat(f);

        Xls.SetCellFormat(2, 1, XF);
        Xls.SetCellFormat(3, 1, XF);

        f.Rotation            = 45;
        f.FillPattern.Pattern = TFlxPatternStyle.Solid;
        int XF2 = Xls.AddFormat(f);

        //Apply a custom format to all the row.
        Xls.SetRowFormat(1, XF2);

        //Merge cells
        Xls.MergeCells(5, 1, 10, 6);
        //Note how this one merges with the previous range, creating a final range (5,1,15,6)
        Xls.MergeCells(10, 6, 15, 6);

        //Make sure rows are autofitted for pdf export.
        Xls.AutofitRowsOnWorkbook(false, true, 1);
    }
Пример #13
0
        public int GetSummationFormat(ExcelFile xls)
        {
            if (summationFormat == null)
            {
                getDefaultFormat            = xls.GetDefaultFormat;
                getDefaultFormat.Font.Style = TFlxFontStyles.Bold;
                summationFormat             = xls.AddFormat(getDefaultFormat);
            }

            return(summationFormat.Value);
        }
Пример #14
0
        /// <summary>
        /// 给单元格清除标注
        /// </summary>
        /// <param name="row">单元格所在行</param>
        /// <param name="col">单元格所在列</param>
        public void ClearCommentInCell(int row, int col)
        {
            // 设置单元格背景色
            TFlxFormat fmt = xls.GetCellVisibleFormatDef(row, col);

            fmt.FillPattern.Pattern = TFlxPatternStyle.None;
            fmt.FillPattern.FgColor = TExcelColor.Automatic;
            xls.SetCellFormat(row, col, xls.AddFormat(fmt));

            // 清除标注内容
            xls.SetComment(row, col, string.Empty);
        }
        public int SetCellBkColor(int Row, int Col, Color bk)
        {
            int        cellFormat = GetCellFormat(Row, Col);
            TFlxFormat format     = GetFormat(cellFormat);

            format.FillPattern.Pattern = TFlxPatternStyle.Solid;
            format.FillPattern.FgColor = bk;

            cellFormat = AddFormat(format);
            SetCellFormat(Row, Col, cellFormat);
            return(cellFormat);
        }
Пример #16
0
        /// <summary>
        /// Returns the sum of cells in a range that have the same color as a reference cell.
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="parameters">In this case we expect 2 parameters, first the reference cell and then
        /// the range in which to sum. We will return an error otherwise.</param>
        /// <returns></returns>
        public override object Evaluate(TUdfEventArgs arguments, object[] parameters)
        {
            #region Get Parameters
            TFlxFormulaErrorValue Err;
            if (!CheckParameters(parameters, 2, out Err))
            {
                return(Err);
            }

            //The first parameter should be a range
            TXls3DRange SourceCell;
            if (!TryGetCellRange(parameters[0], out SourceCell, out Err))
            {
                return(Err);
            }

            //The second parameter should be a range too.
            TXls3DRange SumRange;
            if (!TryGetCellRange(parameters[1], out SumRange, out Err))
            {
                return(Err);
            }
            #endregion

            //Get the color in SourceCell. Note that if Source cell is a range with more than one cell,
            //we will use the first cell in the range. Also, as different colors can have the same rgb value, we will compare the actual RGB values, not the ExcelColors
            TFlxFormat fmt         = arguments.Xls.GetCellVisibleFormatDef(SourceCell.Sheet1, SourceCell.Top, SourceCell.Left);
            int        SourceColor = fmt.FillPattern.FgColor.ToColor(arguments.Xls).ToArgb();

            double Result = 0;
            //Loop in the sum range and sum the corresponding values.
            for (int s = SumRange.Sheet1; s <= SumRange.Sheet2; s++)
            {
                for (int r = SumRange.Top; r <= SumRange.Bottom; r++)
                {
                    for (int c = SumRange.Left; c <= SumRange.Right; c++)
                    {
                        int    XF  = -1;
                        object val = arguments.Xls.GetCellValue(s, r, c, ref XF);
                        if (val is double) //we will only sum numeric values.
                        {
                            TFlxFormat sumfmt = arguments.Xls.GetCellVisibleFormatDef(s, r, c);
                            if (sumfmt.FillPattern.FgColor.ToColor(arguments.Xls).ToArgb() == SourceColor)
                            {
                                Result += (double)val;
                            }
                        }
                    }
                }
            }
            return(Result);
        }
Пример #17
0
        internal int SetCellBkColor(int row, int col, Color bk)
        {
            int        FF = GetCellFormat(row, col);
            TFlxFormat FX = GetFormat(FF);

            FX.FillPattern.Pattern = TFlxPatternStyle.Solid;
            //FX.FillPattern.FgColorIndex = Xls.NearestColorIndex(bk);
            FX.FillPattern.FgColor = bk;

            FF = AddFormat(FX);
            SetCellFormat(row, col, FF);
            return(FF);
        }
Пример #18
0
        private void CopyRowAndColFormat(ExcelFile Workbook, TWaitingCoords Coords, ExcelFile IncludedReport, TXlsCellRange range)
        {
            //Columns go before rows.
            if (CopyColFormats || (InsertMode == TFlxInsertMode.ShiftColRight && (range.Top > 1 || range.Bottom < FlxConsts.Max_Rows + 1)))
            {
                for (int c = range.Left; c < range.Right; c++)
                {
                    if (!IncludedReport.IsNotFormattedCol(c))
                    {
                        int c1 = c - range.Left + Left + Coords.ColOfs;
                        int cw = IncludedReport.GetColWidth(c);
                        Workbook.SetColWidth(c1, cw);

                        int co = IncludedReport.GetColOptions(c);
                        if (cw != IncludedReport.DefaultColWidth || cw != Workbook.DefaultColWidth)
                        {
                            co |= 0x02;                                                                         //the column has no standard width.
                        }
                        Workbook.SetColOptions(c1, co);
                        TFlxFormat fmt = IncludedReport.GetFormat(IncludedReport.GetColFormat(c));
                        fmt.LinkedStyle.AutomaticChoose = false;
                        Workbook.SetColFormat(c1, Workbook.AddFormat(fmt));
                        if (c1 + 1 <= FlxConsts.Max_Columns)
                        {
                            Workbook.KeepColsTogether(c1, c1 + 1, IncludedReport.GetKeepColsTogether(c), true);
                        }
                    }
                }
            }

            if (CopyRowFormats || (InsertMode == TFlxInsertMode.ShiftRowDown && (range.Left > 1 || range.Right < FlxConsts.Max_Columns + 1)))
            {
                for (int r = range.Top; r < range.Bottom; r++)
                {
                    if (!IncludedReport.IsEmptyRow(r))
                    {
                        int r1 = r - range.Top + Top + Coords.RowOfs;
                        Workbook.SetRowHeight(r1, IncludedReport.GetRowHeight(r));
                        Workbook.SetRowOptions(r1, IncludedReport.GetRowOptions(r));
                        TFlxFormat fmt = IncludedReport.GetFormat(IncludedReport.GetRowFormat(r));
                        fmt.LinkedStyle.AutomaticChoose = false;
                        Workbook.SetRowFormat(r1, Workbook.AddFormat(fmt));
                        if (r1 + 1 <= FlxConsts.Max_Rows)
                        {
                            Workbook.KeepRowsTogether(r1, r1 + 1, IncludedReport.GetKeepRowsTogether(r), true);
                        }
                    }
                }
            }
        }
Пример #19
0
        void SetTitleCellFormat(XlsFile xls)
        {
            TFlxFormat cellFormat = xls.GetCellVisibleFormatDef(1, 1);

            cellFormat.Font.Size20         = 240;
            cellFormat.Font.Color          = TExcelColor.FromTheme(TThemeColor.Accent1);
            cellFormat.Font.Style          = TFlxFontStyles.Bold;
            cellFormat.FillPattern.Pattern = TFlxPatternStyle.Solid;
            cellFormat.FillPattern.FgColor = TExcelColor.FromTheme(TThemeColor.Accent3, 0.6);
            cellFormat.VAlignment          = TVFlxAlignment.center;
            cellFormat.HAlignment          = THFlxAlignment.center;

            xls.SetCellFormat(1, 1, xls.AddFormat(cellFormat));
        }
Пример #20
0
        public int GetHeaderFormat(ExcelFile xls)
        {
            if (headerFormat == null)
            {
                headerFormat                = xls.DefaultFormatId;
                getDefaultFormat            = xls.GetDefaultFormat;
                getDefaultFormat.Font.Color = Color.Black;
                getDefaultFormat.VAlignment = TVFlxAlignment.center;
                getDefaultFormat.HAlignment = THFlxAlignment.center;
                getDefaultFormat.WrapText   = true;
                headerFormat                = xls.AddFormat(getDefaultFormat);
            }

            return(headerFormat.Value);
        }
Пример #21
0
        public int GetFootnoteFormat(ExcelFile xls)
        {
            if (footnoteFormat == null)
            {
                footnoteFormat              = xls.DefaultFormatId;
                getDefaultFormat            = xls.GetDefaultFormat;
                getDefaultFormat.HAlignment = THFlxAlignment.left;
                xls.AddFormat(getDefaultFormat);

                getDefaultFormat.HAlignment = THFlxAlignment.right;
                footnoteFormat = xls.AddFormat(getDefaultFormat);
            }

            return(footnoteFormat.Value);
        }
Пример #22
0
        public int GetSectionNameFormat(ExcelFile xls)
        {
            if (sectionNameFormat == null)
            {
                sectionNameFormat                    = xls.DefaultFormatId;
                getDefaultFormat                     = xls.GetDefaultFormat;
                getDefaultFormat.Font.Style          = TFlxFontStyles.Bold;
                getDefaultFormat.Font.Color          = Color.Black;
                getDefaultFormat.FillPattern.Pattern = TFlxPatternStyle.Solid;
                getDefaultFormat.FillPattern.FgColor = Color.Silver;
                getDefaultFormat.HAlignment          = THFlxAlignment.left;
                sectionNameFormat                    = xls.AddFormat(getDefaultFormat);
            }

            return(sectionNameFormat.Value);
        }
Пример #23
0
        public static THFlxAlignment GetDataAlign(TCellType CellType, TFlxFormat Fm)
        {
            switch (Fm.HAlignment)
            {
            case THFlxAlignment.general:
                return(GetGeneralAlign(CellType));

            case THFlxAlignment.center_across_selection:
            case THFlxAlignment.center:
                return(THFlxAlignment.center);

            case THFlxAlignment.right:
                return(THFlxAlignment.right);
            }
            return(THFlxAlignment.left);
        }
Пример #24
0
        public TFlxFormat GetCellVisibleFormatDef(ExcelFile Workbook, int row, int col, bool Merged)
        {
            int XF = Workbook.DefaultFormatId;

            UpdateRowBiggerThan0(Workbook, row, col);

            bool CacheValid = Merged || (LastCachedRowBiggerThan0 && LastCachedColBiggerThan0);

            if (CacheValid)
            {
                if (PageFormatCache != null && PageFormatCache.IsValid(row, col))
                {
                    return(PageFormatCache.GetFormat(row, col));
                }

                XF = Workbook.GetCellVisibleFormat(row, col);
            }

            TFlxFormat Result;

            if (!FlxFormatCache.TryGetValue(XF, out Result))
            {
                Result             = Workbook.GetFormat(XF);
                FlxFormatCache[XF] = Result;
            }

            TFlxFormat Result2 = Workbook.ConditionallyModifyFormat(Result, row, col);

            if (Result2 != null)
            {
                if (PageFormatCache != null && CacheValid)
                {
                    PageFormatCache.SetFormat(row, col, Result2);
                }
                return(Result2);
            }

            if (PageFormatCache != null && CacheValid)
            {
                PageFormatCache.SetFormat(row, col, Result);
            }
            return(Result);
        }
Пример #25
0
        protected override void RenderBody(ExtendedXlsFile xls)
        {
            InternalData.Initialize(GetMaxParentMaxNestingLevel(), Data.VoltageClassPoints);

            TFlxFormat getDefaultFormat = xls.GetDefaultFormat;
            int        formatIndex      = xls.DefaultFormatId;

            xls.ActiveSheet = 1;
            if (InternalData.ExportType == TExportExcelAdapterType.toXLS)
            {
                //getDefaultFormat.Font.Name = "Times New Roman";
                getDefaultFormat.Font.Size20 = 188;
            }
            else
            {
                getDefaultFormat.Font.Size20 = 212;
            }
            xls.SetFormat(formatIndex, getDefaultFormat);
        }
Пример #26
0
        public void AutoRun()
        {
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            ExcelFile Xls = new XlsFile(true);

            Xls.NewFile(1);
            Xls.SetColWidth(1, 78 * 256); //;make longer lines wrap in the cell.
            TFlxFormat fmt = Xls.GetFormat(Xls.GetColFormat(1));

            fmt.WrapText = true;

            Xls.SetColFormat(1, Xls.AddFormat(fmt));
            AddData(Xls);
            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Process.Start(saveFileDialog1.FileName);
            }
        }
Пример #27
0
        private void DoThings()
        {
            ExcelFile xls = new XlsFile(true);

            xls.NewFile(1, TExcelFileFormat.v2019);

            for (int r = 1; r < 2000; r++)
            {
                xls.InsertHPageBreak(r); //This won't throw an exception here, since FlexCel allows to have more than 1025 page breaks, but at the moment of saving. (since an xls file can't have more than that)
            }

            xls.SetCellValue(1, 1, "We have a page break on each row, so this will print/export as one row per page");
            xls.SetCellValue(2, 1, "??? ? ? ? ???? ????"); //Since we leave the font at arial, this won't show when exporting to pdf.

            TFlxFormat fmt = xls.GetDefaultFormat;

            fmt.Font.Name = "Arial Unicode MS";
            xls.SetCellValue(3, 1, "??? ? ? ? ???? ????", xls.AddFormat(fmt)); //this will display fine in the pdf.

            fmt.Font.Name = "ThisFontDoesntExists";
            xls.SetCellValue(4, 1, "This font doesn't exists", xls.AddFormat(fmt));

            //Tahoma doesn't have italic variant. See http://help.lockergnome.com/office/Tahoma-italic-ftopict705661.html
            //You shouldn't normally use Tahoma italics in a document. If we embedded the fonts in this pdf, the fake italics wouldn't work.
            fmt.Font.Name  = "Tahoma";
            fmt.Font.Style = TFlxFontStyles.Italic;
            xls.SetCellValue(5, 1, "This is fake italics", xls.AddFormat(fmt));

            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.Export(Path.ChangeExtension(saveFileDialog1.FileName, ".pdf"));
            }

            xls.Save(saveFileDialog1.FileName + ".xls");
        }
        private void SetCellFloatValue(int Row, int Col, object value, int FloatDecimals, bool IsNeed0)
        {
            if (Col <= 255)
            {
                if (FloatDecimals < 0)
                {
                    FloatDecimals = 0;
                }
                SetCellValue(Row, Col, value);
                string str = string.Empty;
                for (int i = 1; i <= FloatDecimals; i++)
                {
                    str = str + (IsNeed0 ? "0" : "#");
                }
                string str2 = "# ### ### ##0";
                if (str != string.Empty)
                {
                    str2 = str2 + "." + str;
                }

                if (CurrentExportType == TExportExcelAdapterType.toHTML)
                {
                    if (value != null)
                    {
                        SetCellValue(Row, Col, ((double)value).ToString(str2));
                        SetCellAlignH(Row, Col, THFlxAlignment.right);
                        SetCellAlignV(Row, Col, TVFlxAlignment.center);
                    }
                }
                else
                {
                    int        cellFormat = GetCellFormat(Row, Col);
                    TFlxFormat format     = GetFormat(cellFormat);
                    format.Format = str2;
                    cellFormat    = AddFormat(format);
                    SetCellFormat(Row, Col, cellFormat);
                }
            }
        }
Пример #29
0
        internal int AddStyleFormat(TFlxFormat format, string StyleName)
        {
            if (!format.IsStyle)
            {
                format         = (TFlxFormat)format.Clone();
                format.IsStyle = true;
            }

            int OldFmt = Styles.GetStyle(StyleName);

            if (OldFmt >= 0 && OldFmt < StyleXF.Count)
            {
                TXFRecord XF1 = new TXFRecord(format, OldFmt == 0, this, false);
                StyleXF[OldFmt] = XF1;
                CellXF.UpdateChangedStyleInCellXF(OldFmt, XF1, false);
                return(OldFmt);
            }

            TXFRecord XFRec = new TXFRecord(format, false, this, false);

            StyleXF.Add(XFRec);
            return(StyleXF.Count - 1);
        }
Пример #30
0
        /// <summary>
        /// 给单元格添加标注
        /// </summary>
        /// <param name="row">单元格所在行</param>
        /// <param name="col">单元格所在列</param>
        /// <param name="comment">标注</param>
        public void AddCommentToCell(int row, int col, string commentTitle, string commentDetail)
        {
            string comment = string.Format("{0}\n{1}\n", commentTitle, commentDetail);

            // 设置单元格背景色
            TFlxFormat fmt = xls.GetCellVisibleFormatDef(row, col);

            fmt.FillPattern.Pattern = TFlxPatternStyle.Solid;
            fmt.FillPattern.FgColor = Color.FromArgb(0xFF9999);
            xls.SetCellFormat(row, col, xls.AddFormat(fmt));

            // 设置批注
            TRTFRun[] Runs = new TRTFRun[3];
            Runs[0].FirstChar = 0;
            TFlxFont fnt = xls.GetDefaultFont;

            fnt.Size20        = 180;
            fnt.Color         = TExcelColor.Automatic;
            fnt.Style         = TFlxFontStyles.Bold;
            fnt.Family        = 3;
            fnt.CharSet       = 134;
            fnt.Scheme        = TFontScheme.None;
            Runs[0].FontIndex = xls.AddFont(fnt);
            Runs[1].FirstChar = 7;
            fnt               = xls.GetDefaultFont;
            fnt.Size20        = 180;
            fnt.Color         = TExcelColor.Automatic;
            fnt.Family        = 3;
            fnt.CharSet       = 134;
            fnt.Scheme        = TFontScheme.None;
            Runs[1].FontIndex = xls.AddFont(fnt);
            Runs[2].FirstChar = 13;
            fnt               = xls.GetDefaultFont;
            Runs[2].FontIndex = xls.AddFont(fnt);
            xls.SetComment(row, col, new TRichString(comment, Runs, xls));
        }
Пример #31
0
        public TFlxFormat GetColor2(TFlxFormat obj)
        {
            TFlxFillPattern pattern = new TFlxFillPattern();
            pattern.FgColor = Colors.LightGray;
            pattern.Pattern = TFlxPatternStyle.Solid;

            TFlxBorders border = new TFlxBorders();
            border.SetAllBorders(TFlxBorderStyle.Thin, Colors.Black);

            obj.FillPattern = pattern;
            obj.Borders = border;

            return obj;
        }
Пример #32
0
        public TFlxFormat GetBold(TFlxFormat obj)
        {
            TFlxFont tfont = new TFlxFont();
            tfont.Style = TFlxFontStyles.Bold;

            obj.Font = tfont;

            return obj;
        }