Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Apr 05, 2023 10:50 am

Hi, I have an Excel file that contains pivot tables and charts all those depend on data in another sheet X.
The data in the concerned sheet X is loaded from Datatable.
The problem I have is when I work on the origin file and enter the new data manually it works fine: the charts/pivot tables refresh perfectly after generating the PDF,
but when I copy this file to another file and load the new data from the data table then refresh my PivotTables/charts
the refresh works only on the Excel file (sure because IsRefreshOnLoad = true
) but when I generate pdf I find only the PivotTable data updated
. Any help with how could I refresh the charts in the PDF file, please?

My code :
Code: Select all
         //fileToTreat is the original file
         //fileName the destination
         File.Copy(fileToTreat, fileName, true);
         FileInfo file = new FileInfo(fileName);
         using (ExcelPackage excelPackage = new ExcelPackage(file))
         {
              ExcelWorkbook excelWorkBook = excelPackage.Workbook;
              excelWorkBook.Worksheets.Delete("Commandes");
              ExcelWorksheet ws = excelWorkBook.Worksheets.Add("Commandes");
              ws.Cells["A1"].LoadFromDataTable(dtCde, true);
             excelPackage.SaveAs(new FileInfo(fileName));
        }

        Workbook workbook = new Workbook();
        workbook.ConverterSetting.ClearCacheOnConverted = true;
        workbook.LoadFromFile(fileName);
        foreach (Worksheet wb in workbook.Worksheets)
        {
               var pt = wb.PivotTables;
               foreach (Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable item in pt)
                {
                      item.Cache.IsRefreshOnLoad = true;
                      item.CalculateData();
                }
                                   
                var tables = wb.Charts;
                foreach (Chart chart in tables)
                {
                     chart.RefreshChart();
                }
      }

     workbook.SaveToFile(path + "\\" + outFile, ExcelVersion.Version2016);
     workbook.SaveToFile(path + "\\" + outFile, FileFormat.PDF);



Thanks

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Thu Apr 06, 2023 8:41 am

Hi,

Thanks for your message.
Please provide us with the following information for further investigation.
1.Your input Excel files, which you can upload them here or provide to us by email (support@e-iceblue.com)
2.Your system information (E.g. Win10, 64 bit) and region setting (E.g. China, Chinese).

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Thu Apr 06, 2023 9:35 am

Thanks for your return

Here is how I load the data :

Code: Select all
                   DataTable dtCde = new DataTable();
                            dtCde.Columns.Add("Étiquettes de lignes");
                            dtCde.Columns.Add("Qte", typeof(int));
                           
                            result = new List<GetCdeModelario_Result>();
                            result.Add(new GetCdeModelario_Result
                            {
                                QTE = 10000,
                                REFCOL = "003904S 04"
                            });
                            result.Add(new GetCdeModelario_Result
                            {
                                QTE = 20000,
                                REFCOL = "003904S 05"
                            });
                           result.Add(new GetCdeModelario_Result
                            {
                                QTE = 30000,
                                REFCOL = "243853S 17"
                            });
                           result.Add(new GetCdeModelario_Result
                            {
                                QTE = 40000,
                                REFCOL = "363281S 11"
                            });
                            result.Add(new GetCdeModelario_Result
                            {
                                QTE = 50000,
                                REFCOL = "259097S 01"
                            });
                            foreach (var item in result)
                            {
                                DataRow dr = dtCde.NewRow();
                                dr[0] = item.REFCOL;
                                dr[1] = item.QTE;
                                dtCde.Rows.Add(dr);
                            }
                            FileInfo file = new FileInfo(fileName);
                            using (ExcelPackage excelPackage = new ExcelPackage(file))
                            {
                                ExcelWorkbook excelWorkBook = excelPackage.Workbook;
                                excelWorkBook.Worksheets.Delete("Commandes");
                                ExcelWorksheet ws = excelWorkBook.Worksheets.Add("Commandes");
                                ws.Cells["A1"].LoadFromDataTable(dtCde, true);
                                excelPackage.SaveAs(new FileInfo(path + "\\"+outFile));
                            }

   public partial class GetCdeModelario_Result
    {
        public string REFCOL
        {
            get;
            set;
        }
   
        public Nullable<int> QTE
        {
            get;
            set;
        }
    }


You need to load to data from the code because if I add it manually the refresh will work and my goal is to load the data from the database.
If i try using Interop RefreshAll() it works perfectly but I can't use it because I can't install Excel on the server :(
Attachments
Test tcd gra.zip
(31.61 KiB) Downloaded 387 times

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Fri Apr 07, 2023 11:15 am

Hi,

Thanks for your more information.
I found that you used “ExcelPackage” to copy the excel file and insert the data. I used our Spire product to insert some data, after refreshing, the PDF data of the charts and pivot tables both are lost, we will do more tests and update you about the progress accordingly.
Meanwhile, could you help to share your more files as the below screenshot shows. Thanks in advance.
Image
Best Regards,
Herman
E-iceblue support team
Attachments
wewe.png
wewe.png (17.46 KiB) Viewed 1446 times
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Fri Apr 07, 2023 12:10 pm

YES, i used ExcelPackage because I'm trying multiple codes , i used before Spire but not worked for me !

Code: Select all
                        // fileToTreat is the file attached before (the original file)
                       // fileName is a copy of it
                        File.Copy(fileToTreat, fileName, true);

                        using (ServiceReponse repAnalyse = new ServiceReponse()
                        {
                            var result = repAnalyse.GetCde(string.Join(", ", enumerable)).ToList();
                            DataTable dtCde = new DataTable();
                            dtCde.Columns.Add("Étiquettes de lignes");
                            dtCde.Columns.Add("Qte", typeof(int));
                            foreach (var item in result)
                            {
                                DataRow dr = dtCde.NewRow();
                                dr[0] = item.REFCOL;
                                dr[1] = item.QTE;
                                dtCde.Rows.Add(dr);
                            }
                            DataTable dtAnalyse = new DataTable();                               

                            //epplus
                            FileInfo file = new FileInfo(fileName);
                            using (ExcelPackage excelPackage = new ExcelPackage(file))
                            {
                                ExcelWorkbook excelWorkBook = excelPackage.Workbook;
                                excelWorkBook.Worksheets.Delete("Commandes");
                                ExcelWorksheet ws = excelWorkBook.Worksheets.Add("Commandes");
                                ws.Cells["A1"].LoadFromDataTable(dtCde, true);
                                ws.Hidden = OfficeOpenXml.eWorkSheetHidden.Hidden;
                             
                                var activeSheets = excelWorkBook.Worksheets.Where(ff => ff.View.TabSelected).ToList();

                                if (activeSheets != null)
                                    foreach(var sheet in activeSheets)
                                    excelWorkBook.Worksheets[sheet.Name].View.SetTabSelected(true,true);

                                foreach(var sheet in excelWorkBook.Worksheets.ToList())
                                {
                                    if(sheet.Hidden == eWorkSheetHidden.Visible)
                                    {
                                        sheet.Hidden = OfficeOpenXml.eWorkSheetHidden.Visible;
                                    }
                                    else if(sheet.Hidden == eWorkSheetHidden.Hidden)
                                    {
                                        sheet.Hidden = OfficeOpenXml.eWorkSheetHidden.Hidden;
                                    }
                                }
                               
                                excelPackage.SaveAs(new FileInfo(path + "\\"+outFile));

                                Workbook workbook = new Workbook();
                                workbook.ConverterSetting.ClearCacheOnConverted = true;
                                workbook.LoadFromFile(path + "\\" + outFile);
                                foreach (Worksheet wb in workbook.Worksheets)
                                {
                                    var pt = wb.PivotTables;
                                    foreach (Spire.Xls.Core.Spreadsheet.PivotTables.XlsPivotTable item in pt)
                                    {
                                        item.Cache.IsRefreshOnLoad = true;
                                        item.CalculateData();
                                    }
                                   
                                    var tables = wb.Charts;
                                    foreach (Chart chart in tables)
                                    {
                                        chart.RefreshChart();
                                    }
                                }

                                workbook.SaveToFile(path + "\\" + outFile, ExcelVersion.Version2016);
                                workbook.SaveToFile(path + "\\" + outFile, FileFormat.PDF);

                            }

                            }
                 


Even I tried to convert the Excel file to PDF but no result!
The attached file contains: the fileToTreat , the fileName which is the outputFile XLSX, and the PDF you will find that the PDF is missing the chart refresh
Attachments
files.zip
(90.39 KiB) Downloaded 424 times

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Mon Apr 10, 2023 9:35 am

Hi,

Thanks for your feedback.
I did reproduce your issue after testing your excel files. I have logged this issue into our tracking system with the ticket SPIREXLS-4605, our Dev team will do further investigation and fixing. Once there is any update, we will keep you informed. Sorry for the inconvenience caused.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Mon Apr 10, 2023 1:02 pm

Thanks ! :)

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Mon Apr 17, 2023 3:50 pm

Hi
Any updates please ?

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Tue Apr 18, 2023 1:47 am

Hi,

Thank you for following up.
I have been informed that the issue SPIREXLS-4605 is currently in the testing phase. Please allow us a little more time to complete the testing. Once the tests passes, I will inform you of the new version as soon as possible. Thank you for your patience and understanding.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Tue May 02, 2023 8:56 am

Any news, please ?

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Tue May 02, 2023 9:31 am

Hello,

Thanks for your following up.
Sorry the first test is failed. Our Dev is currently adjusting the internal code, and we will notify you as soon as there is any progress. Thank you for your understanding.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Mon May 29, 2023 11:04 am

Hi :)
Any news ?

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Tue May 30, 2023 10:05 am

Hello,

Thanks for your message.
Regarding the SPIREXLS-4605 issue of chart data not being refreshed, it has passed the tests. Our testing team is merging the code and compiling the release package now. Once it's available, we will inform you as soon as. Thank you for your understanding.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Thu Jun 01, 2023 9:15 am

Hello,

Glad to inform that we just released Spire.XLS Pack(Hotfix) Version:13.5.6 which includes the adjustment of the SPIREXLS-4605, please download it from the following links to test.
Website link: https://www.e-iceblue.com/Download/download-excel-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.XLS/13.5.6

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1271
Joined: Wed Apr 25, 2018 3:20 am

Mon Jun 05, 2023 5:08 pm

Can you please give me the code that has been used?

siwarh1996
 
Posts: 8
Joined: Tue Apr 04, 2023 1:27 pm

Return to Spire.XLS