Error In Output File After Replacing Strings

I’m processing the input file attached and the output file is giving me some errors when I open it. Both input and output files are attached for reference. The code is the following:


Hashtable hsTagsRegs = new Hashtable();
hsTagsRegs.Add("##DatImp", new DateTime(2011, 06, 15, 17, 05, 00));
hsTagsRegs.Add("##NmeElb", “Siteware”);
hsTagsRegs.Add("##DatApr", “”);
hsTagsRegs.Add("##SigUni", “SiteAir 2011”);
hsTagsRegs.Add("##TitDoc", “TESTE ROGGER”);
hsTagsRegs.Add("##NmeVrf", “”);
hsTagsRegs.Add("##DatVrf", “”);
hsTagsRegs.Add("##TipCop", “Copia Não Controlada”);
hsTagsRegs.Add("##DatCri", new DateTime(2011, 06, 14, 11, 10, 06));
hsTagsRegs.Add("##NumRev", “0”);
hsTagsRegs.Add("##NmeApr", “Siteware”);
hsTagsRegs.Add("##CodDoc", “AI_Site_Air2011_009”);

Dim xls As New Workbook(pFileName)
For i As Integer = 0 To xls.Worksheets.Count - 1
For Each item As DictionaryEntry In htVarConf

Dim pageSetup As Aspose.Cells.PageSetup = xls.Worksheets(i).PageSetup
For j As Integer = 0 To 2

Dim header As String = pageSetup.GetHeader(j)
If header <> Nothing And header <> “” Then
header = header.Replace(item.Key.ToString(), item.Value.ToString())
pageSetup.SetHeader(j, header)
End If

Dim footer As String = pageSetup.GetFooter(j)
If footer <> Nothing And footer <> “” Then
footer = footer.Replace(item.Key.ToString(), item.Value.ToString())
pageSetup.SetFooter(j, footer)
End If
Next
xls.Worksheets(i).Replace(item.Key.ToString(), item.Value.ToString())
Next
Next

xls.Save(processedFile, Aspose.Cells.SaveFormat.Auto)

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version:
Aspose.Cells
for .NET v7.1.2.7

and let us know your feedback.

If the problem still occurs, I will also require your sample runnable project. replicating the problem.

Your code is mixed up of C# and VB.NET.

The error still occurs. Below is the code I’m using.


Dim hsTagsRegs As New Hashtable()
hsTagsRegs.Add("##DatImp", new DateTime(2011, 06, 15, 17, 05, 00))
hsTagsRegs.Add("##NmeElb", “Siteware”)
hsTagsRegs.Add("##DatApr", “”)
hsTagsRegs.Add("##SigUni", “SiteAir 2011”)
hsTagsRegs.Add("##TitDoc", “TESTE ROGGER”)
hsTagsRegs.Add("##NmeVrf", “”)
hsTagsRegs.Add("##DatVrf", “”)
hsTagsRegs.Add("##TipCop", “Copia Não Controlada”)
hsTagsRegs.Add("##DatCri", new DateTime(2011, 06, 14, 11, 10, 06))
hsTagsRegs.Add("##NumRev", “0”)
hsTagsRegs.Add("##NmeApr", “Siteware”)
hsTagsRegs.Add("##CodDoc", “AI_Site_Air2011_009”)

Dim xls As New Workbook(pFileName)
For i As Integer = 0 To xls.Worksheets.Count - 1
For Each item As DictionaryEntry In htVarConf

Dim pageSetup As Aspose.Cells.PageSetup = xls.Worksheets(i).PageSetup
For j As Integer = 0 To 2

Dim header As String = pageSetup.GetHeader(j)
If header <> Nothing And header <> “” Then
header = header.Replace(item.Key.ToString(), item.Value.ToString())
pageSetup.SetHeader(j, header)
End If

Dim footer As String = pageSetup.GetFooter(j)
If footer <> Nothing And footer <> “” Then
footer = footer.Replace(item.Key.ToString(), item.Value.ToString())
pageSetup.SetFooter(j, footer)
End If
Next
xls.Worksheets(i).Replace(item.Key.ToString(), item.Value.ToString())
Next
Next

xls.Save(processedFile, Aspose.Cells.SaveFormat.Auto)

Hi,

Please see the code below, it is working fine.

Please use the following save formats.

1) Xls - Aspose.Cells.SaveFormat.Excel97To2003

  1. Xlsx - Aspose.Cells.SaveFormat.Xlsx

    It will work fine.

    VB.NET

    Dim filePath As String = “F:\Shak-Data-RW\Downloads\INPUT+1.xls”


    Dim hsTagsRegs As New Hashtable()

    hsTagsRegs.Add("##DatImp", New DateTime(2011, 6, 15, 17, 5, 0))

    hsTagsRegs.Add("##NmeElb", “Siteware”)

    hsTagsRegs.Add("##DatApr", “”)

    hsTagsRegs.Add("##SigUni", “SiteAir 2011”)

    hsTagsRegs.Add("##TitDoc", “TESTE ROGGER”)

    hsTagsRegs.Add("##NmeVrf", “”)

    hsTagsRegs.Add("##DatVrf", “”)

    hsTagsRegs.Add("##TipCop", “Copia Não Controlada”)

    hsTagsRegs.Add("##DatCri", New DateTime(2011, 6, 14, 11, 10, 6))

    hsTagsRegs.Add("##NumRev", “0”)

    hsTagsRegs.Add("##NmeApr", “Siteware”)

    hsTagsRegs.Add("##CodDoc", “AI_Site_Air2011_009”)


    Dim xls As New Workbook(filePath)

    For i As Integer = 0 To xls.Worksheets.Count - 1

    For Each item As DictionaryEntry In hsTagsRegs


    Dim pageSetup As Aspose.Cells.PageSetup = xls.Worksheets(i).PageSetup

    For j As Integer = 0 To 2


    Dim header As String = pageSetup.GetHeader(j)

    If header <> Nothing And header <> “” Then

    header = header.Replace(item.Key.ToString(), item.Value.ToString())

    pageSetup.SetHeader(j, header)

    End If


    Dim footer As String = pageSetup.GetFooter(j)

    If footer <> Nothing And footer <> “” Then

    footer = footer.Replace(item.Key.ToString(), item.Value.ToString())

    pageSetup.SetFooter(j, footer)

    End If

    Next

    xls.Worksheets(i).Replace(item.Key.ToString(), item.Value.ToString())

    Next

    Next


    xls.Save(filePath + “.out.xls”, Aspose.Cells.SaveFormat.Excel97To2003)



I’m getting the error when I try to open the file on the Word 2007. On the Word 2010 it works just fine.

Hi,

Why are you opening Ms-Excel file into Ms-Word application.

I think, you meant Ms-Excel 2007, I tried opening it and did not face any trouble. Please see the screenshot.

Could you provide us your screenshot showing the problem?

Screenshot:

Sorry… I’m opening in Excel.

See the Screenshot:


Hi,

Thanks for your screenshot.

I think, you are opening some other file.

Please open this file and see if the same error occurs. Let me know your feedback.

INPUT+1.xls.out.xls