Пример #1
0
        private ExcelFile Consolidate(Stream[] fileDatas, string[] fileNames, bool OnlyData)
        {
            ExcelFile XlsIn  = new XlsFile();
            ExcelFile XlsOut = new XlsFile(true);

            XlsOut.NewFile(1);

            if (fileNames.Length > 1 && cbOnlyData.Checked)
            {
                XlsOut.InsertAndCopySheets(1, 2, fileNames.Length - 1);
            }

            for (int i = 0; i < fileNames.Length; i++)
            {
                if (fileDatas != null)
                {
                    XlsIn.Open(fileDatas[i]);
                }
                else
                {
                    XlsIn.Open(fileNames[i]);
                }
                XlsIn.ConvertFormulasToValues(true); //If there is any formula referring to other sheet, convert it to value.
                                                     //We could also call an overloaded version of InsertAndCopySheets() that
                                                     //copies many sheets at the same time, so references are kept.
                XlsOut.ActiveSheet = i + 1;

                if (OnlyData)
                {
                    XlsOut.InsertAndCopyRange(TXlsCellRange.FullRange(), 1, 1, 1, TFlxInsertMode.ShiftRangeDown, TRangeCopyMode.All, XlsIn, 1);
                }
                else
                {
                    XlsOut.InsertAndCopySheets(1, XlsOut.ActiveSheet, 1, XlsIn);
                }

                //Change sheet name.
                string s = Path.GetFileName(fileNames[i]);
                if (s.Length > 32)
                {
                    XlsOut.SheetName = s.Substring(0, 29) + "...";
                }
                else
                {
                    XlsOut.SheetName = s;
                }
            }

            if (!cbOnlyData.Checked)
            {
                XlsOut.ActiveSheet = XlsOut.SheetCount;
                XlsOut.DeleteSheet(1);  //Remove the empty sheet that came with the workbook.
            }

            XlsOut.ActiveSheet = 1;
            return(XlsOut);
        }
Пример #2
0
        private void AutoRun()
        {
            //We will use data already stored in a file. For a real case, you would
            //probably fill this data from some database.
            string    fileName = Path.Combine(PathToExe, "git-stats.xlsx");
            ExcelFile Xls      = new XlsFile(fileName, true);

            //Add a new empty sheet for adding the chart.
            Xls.InsertAndCopySheets(0, 1, 1);
            Xls.ActiveSheet      = 1;
            Xls.SheetName        = "Chart";
            Xls.PrintToFit       = true;
            Xls.PrintScale       = 70;
            Xls.PrintXResolution = 600;
            Xls.PrintYResolution = 600;
            Xls.PrintOptions     = TPrintOptions.None;
            Xls.PrintPaperSize   = TPaperSize.Letter;
            Xls.PrintLandscape   = true;

            AddChart(Xls);
            NormalOpen(Xls);
        }