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 Aug 04, 2021 11:10 am

Hello,
When converting an Excel file to PDF, the columns are displayed incorrectly.
We use the following code:
Code: Select all
...
 var workbook = FitWorkbook(content);

            if (customFontFilePaths.Length > 0)
                workbook.CustomFontFilePaths = customFontFilePaths.Split(",");
            else
                workbook.CustomFontFilePaths = new string[]
                    {
                            "/usr/share/fonts/truetype/msttcorefonts/times.ttf",
                            "/usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf",
                            "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",
                            "/usr/share/fonts/truetype/msttcorefonts/georgiab.ttf"
                    };

                  using (var stream = new MemoryStream())               
                     {
                           workbook.SaveToStream(stream, Spire.Xls.FileFormat.PDF);
                           return File(stream.ToArray(), "application/pdf", "convert.pdf");
                     }

...

        private Workbook FitWorkbook(byte[] content)
        {
            Workbook workbook = new();
            using (var stream = new MemoryStream(content))
            {
                workbook.LoadFromStream(stream, true);

                // fitting line heights
                FitMergedRows(workbook);

                return workbook;
            }
        }




private void FitMergedRows(Workbook workbook)
        {
            for (int i = 0; i < workbook.Worksheets.Count; i++)
            {                           
                var sheet = workbook.Worksheets[i];
                var ranges = sheet.MergedCells;

                if (sheet.AllocatedRange == null)
                    continue;

                var startedColumnIndex = sheet.Columns.Length;
                var fitColumnIndex = startedColumnIndex;

                for (int j = 0; j < ranges.Count(); j++)
                    sheet[1, sheet.Columns.Length + 1].Value = j.ToString();

                foreach (var range in ranges)
                {
                    if (range.RowCount > 1 || range.DisplayedText.Length < 1)
                        continue;

                    fitColumnIndex++;

                    var columnWidth = 0.0;                   

                    foreach (var cell in range.CellList)
                        columnWidth += cell.ColumnWidth;

                    sheet.SetColumnWidth(fitColumnIndex, columnWidth);
                    sheet.Rows[range.Row - 1].CellList[fitColumnIndex - 1].Value = range.DisplayedText.Replace(System.Environment.NewLine, " ");

                    if (range.CellsCount > 0)
                        sheet.Rows[range.Row - 1].CellList[fitColumnIndex - 1].Style = range.Cells[0].Style;                       

                    sheet.Rows[range.Row - 1].CellList[fitColumnIndex - 1].Style.WrapText = true;
                }

                try
                {                   
                    sheet.AllocatedRange.AutoFitRows();
                }
                catch (Exception e)
                {
                    throw new Exception($"error AutoFitRows: {e.Message}", e);
                }
                       
                sheet.DeleteColumn(startedColumnIndex, sheet.Columns.Count() - 1);
            }
        }


use Asp.net Core Web App Net 5.0,
OS: Windows 10 (local testing), docker linux
Spire Library: Spire.Office (6.7.0) & Spire.Xls (11.7.0)

In the attached archive sample files.

Thank you
Attachments
Sample.rar
(96.37 KiB) Downloaded 401 times

s.shevyakov
 
Posts: 18
Joined: Thu Jul 15, 2021 8:42 am

Thu Aug 05, 2021 3:15 am

Hello,

Thanks for your inquiry.
I tested your case and did reproduce your issue. I have logged it in our bug tracking system with the ticket SPIREXLS-3386. If there is any update, we will let you know. Apologize for the inconvenience caused.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Aug 13, 2021 7:45 am

Good afternoon, I would like to know if there have been any updates on the above issue, in particular on the spire.office 6.7.0 library?

The fact is that we have purchased a license for this library, but we cannot yet use it in full.

Thanks

Best regards, Stanislav Shevyakov

s.shevyakov
 
Posts: 18
Joined: Thu Jul 15, 2021 8:42 am

Fri Aug 13, 2021 8:31 am

Hello,

Thanks for your follow up.
I just check the status of the issue SPIREXLS-3386 but found that it has not been solved. Our Dev team is still investigating your issue. Anyway, I have requested them to share any possible ETA at their earliest time. We will inform you as soon as there is any update.
Besides, we don't find the purchase information related to your register email. Could you please provide your Order number or purchase email so that we could record your purchase information?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Aug 16, 2021 6:45 am

Hello,

Our number: Order No.9819

Best Regards, Stanislav Shevyakov

s.shevyakov
 
Posts: 18
Joined: Thu Jul 15, 2021 8:42 am

Mon Aug 16, 2021 7:50 am

Hello,

Thank you very much for sharing your purchase information.
As for the issue SPIREXLS-3386, we will keep you informed if there is any update.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Aug 24, 2021 10:54 am

Hello, I would like to clarify with you how things are progressing on the task SPIREXLS-3386. Are there any changes? Thank you.

s.shevyakov
 
Posts: 18
Joined: Thu Jul 15, 2021 8:42 am

Wed Aug 25, 2021 2:23 am

Hello,

Thanks for your follow up.
I just checked the status of your issue and found it had been fixed. It is now under the testing phase. Once it passes the test, we will compile a new version for you.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Oct 29, 2021 1:40 am

Hello,

Greetings from E-iceblue!
Glad to inform you that we just released Spire.Office Platinum(Hotfix) Version:6.10.3 which fixes the issue SPIREXLS-3386, please download it from the following links to test on your side. Looking forward to your test result.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.Office/6.10.3
https://www.nuget.org/packages/Spire.Of ... ore/6.10.3

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.XLS