Page 1 of 1

Worksheets with a comma in the name

PostPosted: Thu May 27, 2021 9:40 am
by olefebvre
Hello,

Formulas containing a reference to a cell, which is in a worksheet whose name contains a comma, replace the cell's value with "sprᶐ", or something like that, instead of the original value/formula.
I was able to reproduce the problem with the code below, but I didn't try to reproduce it any other way, so the problem can probably be reproduced by working directly with the formula.
Also, there seems to be a problem in the name of the worksheet that was copied into the output workbook.

I have attached a screenshot of the file generated by the code to show you the problem in the cell as well as in the name of the tab in output.
I have also attached an example of a workbook in the "Input.zip" file.

Below is the code used to reproduce the problem (for Windows). I would like to point out that "Input.xlsx" was created manually.

Code: Select all
using System;
using System.IO;
using Spire.Xls;

namespace Test
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            const string basePath = @"C:\Path\To\Your\Directory\";

            string sourceFilePath = Path.Combine(basePath, "Input.xlsx");
            Workbook sourceWorkbook = new Workbook();
            sourceWorkbook.LoadFromFile(sourceFilePath);

            string targetFilePath = Path.Combine(basePath, "Output.xlsx");
            Workbook targetWorkbook = new Workbook();
            Worksheet worksheetToCopy = sourceWorkbook.Worksheets[0];
            targetWorkbook.Worksheets.AddCopy(worksheetToCopy);
         
            targetWorkbook.SaveToFile(targetFilePath, FileFormat.Version2016, true);

            Console.ReadLine();
        }
    }
}

Re: Worksheets with a comma in the name

PostPosted: Thu May 27, 2021 11:50 am
by Annika.Zhou
Hello,

Thanks for your inquiry.
I tested your case and indeed found the behaviour you faced, after investigation, I found it was caused by that the formula used in sheet1 references the value of another sheet named 1,1. If you only copy the sheet1, the formula cannot find the reference. In order to avoid this issue, please refer to the following code to copy the 1,1 sheet.
Code: Select all
 
            const string basePath = @"";         
            string sourceFilePath = Path.Combine(basePath, "Input.xlsx");
            Workbook sourceWorkbook = new Workbook();
            sourceWorkbook.LoadFromFile(sourceFilePath);

            string targetFilePath = Path.Combine(basePath, "Output.xlsx");
            Workbook targetWorkbook = new Workbook();
            targetWorkbook.Worksheets.Clear();

            Worksheet worksheetToCopy = sourceWorkbook.Worksheets["1,1"];
            targetWorkbook.Worksheets.AddCopy(worksheetToCopy);
            worksheetToCopy = sourceWorkbook.Worksheets[0];
            targetWorkbook.Worksheets.AddCopy(worksheetToCopy);

            targetWorkbook.SaveToFile(targetFilePath, FileFormat.Version2016, true);

            Console.ReadLine();


Sincerely,
Annika
E-iceblue support team

Re: Worksheets with a comma in the name

PostPosted: Thu May 27, 2021 12:49 pm
by olefebvre
Hello,

Sorry, I completely forgot to provide you with a part of my code that took care of replacing the cells' content by their value without the formulas, but I did that on the copied worksheet, not on the original one...

You put me on the right track and the problem is solved, thank you.

Re: Worksheets with a comma in the name

PostPosted: Fri May 28, 2021 1:41 am
by Annika.Zhou
Hello,

You're welcome.
If you have other questions about using Spire.XLS in the future, please feel free to contact us.

Sincerely,
Annika
E-iceblue support team