I’ve pasted some code that will mimic what we’re seeing. I’ve also attached the relevant input/output files. You’ll notice the interop output is about 3.6 kb larger.
One of the problems we’re having with the Aspose output is that it doesn’t generate the tags. A search for “NamedCell” doesn’t return any results.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Cells;
namespace ExcelTransform
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string startupPath = AppDomain.CurrentDomain.BaseDirectory;
string filePath = startupPath + “TemplateExcel.xls”;
string asposeOutputPath = startupPath + “AsposeOutput.xml”;
string interopOutputPath = startupPath + “InteropOutput.xml”;
AsposeExcelTransform asposeExcelTransform = new AsposeExcelTransform(filePath);
asposeExcelTransform.SaveWorkbookAsXml(asposeOutputPath);
InteropExcelTransform interopExcelTransform = new InteropExcelTransform(filePath);
interopExcelTransform.SaveWorkbookAsXml(interopOutputPath);
interopExcelTransform.CleanupExcel();
}
}
public class AsposeExcelTransform
{
protected Workbook AsposeWorkbook { get; set; }
public AsposeExcelTransform(string filePath)
{
try
{
//Create a Stream object
FileStream fstream = new FileStream(filePath, FileMode.Open);
//Creating a Workbook object, open the file from a Stream object
//that contains the content of file and it should support seeking
AsposeWorkbook = new Workbook(fstream);
}
catch (Exception ex)
{
AsposeWorkbook = null;
var errorMessage = ex.Message + "\n ||| " + ex.StackTrace;
}
}
public void SaveWorkbookAsXml(string outputPath)
{
SaveWorkbookAsXml(AsposeWorkbook, outputPath);
}
public static void SaveWorkbookAsXml(Workbook workbook, string outputPath)
{
//Save in SpreadsheetML format;
SpreadsheetML2003SaveOptions saveOptions = new
SpreadsheetML2003SaveOptions();
saveOptions.ExportColumnIndexOfCell = true;
saveOptions.SortNames = true;
workbook.Save(outputPath, saveOptions);
}
}
public class InteropExcelTransform
{
protected Microsoft.Office.Interop.Excel.Application InteropExcel { get; set; }
private Microsoft.Office.Interop.Excel.Workbook InteropWorkbook { get; set; }
static readonly object Missing = Type.Missing;
public InteropExcelTransform(string filePath)
{
try
{
InteropExcel = new Microsoft.Office.Interop.Excel.Application
{
DisplayAlerts = false,
Visible = false
};
InteropWorkbook = InteropExcel.Workbooks.Open(filePath, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing);
}
catch (Exception ex)
{
var errorMessage = ex.Message + "\n ||| " + ex.StackTrace;
}
}
public void CleanupExcel()
{
try
{
if ((InteropWorkbook != null))
{
InteropWorkbook.Close(false, Missing, Missing);
InteropWorkbook = null;
}
if (InteropExcel != null)
{
InteropExcel.Quit();
Marshal.ReleaseComObject(InteropExcel);
InteropExcel = null;
}
}
catch (Exception ex)
{
var errorMessage = ex.Message + "\n ||| " + ex.StackTrace;
}
}
public void SaveWorkbookAsXml(string outputPath)
{
SaveWorkbookAsXml(InteropWorkbook, outputPath);
}
public static void SaveWorkbookAsXml(Microsoft.Office.Interop.Excel.Workbook workbook, string outputPath)
{
// Save the workbook
workbook.SaveAs(outputPath, // Filename
Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet, //FileFormat
Missing, // Password
Missing, // WriteResPassword
Missing, // ReadOnlyRecommended
Missing, // CreateBackup
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, // AccessMode
Missing, // ConflictResolution
Missing, // AddToMru
Missing, // TextCodepage
Missing, // TextVisualLayout
Missing); // Local
}
}
}