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.

Tue Jul 23, 2019 10:25 am

Hi,

I using FreeSpire(9.2.1) create a chart and want to export to excel and pdf. But when export to excel the data is correct but label is incorrect. When export to pdf the label is correct but the data is incorrect.

Chart in Excel:
in_excel.PNG
the chart from excel file
in_excel.PNG (47.73 KiB) Viewed 1122 times

Chart in PDF:
in_pdf.PNG
the chart from pdf file
in_pdf.PNG (45.66 KiB) Viewed 1122 times


Here a part of my code:
Code: Select all
public Stream ExportReportingPricedOrder(bool exportAsPdf, ExcelReportingModel model)
        {
            Workbook workbook = new Workbook();
            workbook.Worksheets.Clear();

            var sheet = workbook.CreateEmptySheet();
            sheet.Name = "Data";
            AddHeader(sheet, model);

            AddTable(sheet, model);

            if (model.Chart != null)
            {
                AddBarLineCombinationChar(workbook, model);
            }

            for (int i = 1; i < sheet.LastColumn; i++)
            {
                sheet.AutoFitColumn(i);
            }
            sheet.PageSetup.TopMargin = 0.25;
            sheet.PageSetup.LeftMargin = 0.25;
            sheet.PageSetup.RightMargin = 0.25;
            sheet.PageSetup.BottomMargin = 0.25;
            sheet.PageSetup.HeaderMarginInch = 0;
            sheet.PageSetup.FooterMarginInch = 0;
            var stream = new MemoryStream();
            if (exportAsPdf)
            {
                workbook.ConverterSetting.SheetFitToPage = true;
                workbook.SaveToStream(stream, Spire.Xls.FileFormat.PDF);
            }
            else
            {
                workbook.SaveToStream(stream, Spire.Xls.FileFormat.Version2007);
                stream.Seek(0, SeekOrigin.Begin);
            }
            return stream;
        }


Code: Select all
private void AddBarLineCombinationChar(Workbook workbook, ExcelReportingModel model)
        {
            var dataSheet = workbook.Worksheets[0];
            var chart = workbook.Charts.Add();
            chart.Name = "Chart";
            chart.ChartTitle = model.Title;
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 12;
            chart.SeriesDataFromRange = false;

            foreach (var col in model.Chart.SerieColumns)
            {
                var serie = chart.Series.Add();
                serie.Name = col.Header;
                serie.CategoryLabels = dataSheet.Range[startRow + 1, model.Chart.CategoryColumn.Order, model.Chart.CategoryColumn.Values.Count + startRow + 1, model.Chart.CategoryColumn.Order];
                serie.Values = dataSheet.Range[startRow + 1, startCol + col.Order - 1, col.Values.Count + startRow + 1, startCol + col.Order - 1];
                serie.SerieType = col.ChartType == ChartType.Bar ? ExcelChartType.ColumnClustered : ExcelChartType.LineMarkers;
                serie.UsePrimaryAxis = col.IsUsePrimaryAxis;
            }

            chart.SecondaryCategoryAxis.IsMaxCross = true;
        }


Here is how the data look like:
data.PNG
the data
data.PNG (33.59 KiB) Viewed 1120 times


Any help would be apreciated. I waste so much time on this.

Thanks,
Thanh Phan

trungthanhbp
 
Posts: 1
Joined: Tue Jul 23, 2019 10:15 am

Wed Jul 24, 2019 10:46 am

Hello,

Thanks for your inquiry.
I did an initial test and indeed found that the data was incorrect when exporting to PDF. But when I exported to an excel, both the data and label are correct. Here I attached my full testing code and output files for your reference. Please have a check. If there is any question, just feel free to write back.
Meanwhile, the "data incorrect" issue of PDF has been logged into our bug tracking system for further investigating and fixing. If there is any progress, we will let you know. Sorry for the inconvenience caused.

Sincerely,
Rachel
E-iceblue support team
Attachments
MyTest.rar
(23.62 KiB) Downloaded 167 times
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Aug 15, 2019 9:45 am

Hello,

Glad to inform that we have just released Spire.XLS Pack(Hotfix) Version:9.8.5 which fixes the issue that casued incorrect chart data when exporting to PDF. Please download it from the following links and test.
Website: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget: https://www.nuget.org/packages/Spire.XLS/9.8.5

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS