I use FreeSpire.xls V.8.3.0 installed via NuGet and Excel 365 / Windows 10 with Visual Studio 2017 / C#.
I try to open a xlsx file "Test.xlsx" and replace a text.
When I open the resulting "Replaced.xlsx" Excel shows me an error :
(The message is in german language.... I try to translate)
There was a problem with the content.
Should we repair ?
If I cklick yes I get a message
Excel file is damaged
What could be the problem ?
Code:
- Code: Select all
using Spire.Xls;
using Spire.Pdf;
using Spire.Xls.Converter;
namespace Excel2PDF_Spire
{
class Program
{
static void Main(string[] args)
{
start();
}
static void start()
{
//Create a new workbook
Workbook workbook = new Workbook();
//Load a file and imports its data
workbook.LoadFromFile(@"c:\temp\Test.xlsx");
//Initialize worksheet
Worksheet sheet = workbook.Worksheets[0];
//do something
replaceText(sheet, "Test1", "neuer Text Test1");
//save result
workbook.SaveToFile(@"c:\temp\Replaced.xlsx");
}
static void replaceText(Worksheet sheet, string orginalText, string newText)
{
CellRange[] ranges = sheet.FindAllString(orginalText, false, false);
foreach (CellRange range in ranges)
{
range.Text = newText;
}
}
}