Exemplo n.º 1
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;
        }
Exemplo n.º 2
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);
    }