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.

Thu May 27, 2021 9:40 am

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();
        }
    }
}
Attachments
Input.zip
Input file to use with the C# code.
(6.78 KiB) Downloaded 191 times
strwinclt_cGhzy0zVLW.png
Screenshot of the copied worksheet in the output file "Output.xlsx" generated by the C# code.
strwinclt_cGhzy0zVLW.png (46.13 KiB) Viewed 1514 times

olefebvre
 
Posts: 13
Joined: Wed May 26, 2021 11:36 am

Thu May 27, 2021 11:50 am

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
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Thu May 27, 2021 12:49 pm

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.

olefebvre
 
Posts: 13
Joined: Wed May 26, 2021 11:36 am

Fri May 28, 2021 1:41 am

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
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS