I have text that contains ascii character 22, and maybe some other random ones as well. When I try to write these to the spreadsheet it acts like it worked but then I can't open the file in Excel (see code). I will probably end up writing code to clean these out of my string, but it would be nice to know if this is by design or not.
----Code----
Imports OfficeOpenXml
Imports System.IO
Module Module1
Sub Main()
Dim savepath As String = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".xlsx")
Using xlPackage As New ExcelPackage()
Dim xlWorkSheet = xlPackage.Workbook.Worksheets.Add("Test Sheet")
xlWorkSheet.Cells(1, 1).Value = " " 'ascii value 22 goes here, codeplex won't let me post bug with that value in the body though :)
xlPackage.SaveAs(New FileInfo(savepath))
End Using
Console.WriteLine("Saved to " + savepath)
Console.ReadLine()
End Sub
End Module
Comments: Sharandeep, Sometimes you just have bad data and you need to clean it up. Do a string replace on your data before inserting it. Something like: string valuetoClean = "some value with possibly bad data"; string hex = "0x1F".Substring(2); // To remove leading 0x int num = int.Parse(hex, NumberStyles.AllowHexSpecifier); char cnum = (char)num; string finalValue = valuetoClean.Replace(cnum,'');
----Code----
Imports OfficeOpenXml
Imports System.IO
Module Module1
Sub Main()
Dim savepath As String = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".xlsx")
Using xlPackage As New ExcelPackage()
Dim xlWorkSheet = xlPackage.Workbook.Worksheets.Add("Test Sheet")
xlWorkSheet.Cells(1, 1).Value = " " 'ascii value 22 goes here, codeplex won't let me post bug with that value in the body though :)
xlPackage.SaveAs(New FileInfo(savepath))
End Using
Console.WriteLine("Saved to " + savepath)
Console.ReadLine()
End Sub
End Module
Comments: Sharandeep, Sometimes you just have bad data and you need to clean it up. Do a string replace on your data before inserting it. Something like: string valuetoClean = "some value with possibly bad data"; string hex = "0x1F".Substring(2); // To remove leading 0x int num = int.Parse(hex, NumberStyles.AllowHexSpecifier); char cnum = (char)num; string finalValue = valuetoClean.Replace(cnum,'');