I have a product that converts files to Text for searching. Currently we are testing Aspose to see if it will address this challenge in a more efficient way but we are running into some serious performance issues.
public static string ConvertExcelFileToTextString(string i_ExcelFilePath)
{
Aspose.Cells.License lic = new Aspose.Cells.License();
lic.SetLicense(".\\Component\\Aspose.Total.lic");
// Load your source workbook
Workbook workbook = new Workbook(i_ExcelFilePath);
//0-byte array
byte[] workbookData = new byte[0];
// Text save options. You can use any type of separator
TxtSaveOptions opts = new TxtSaveOptions(Aspose.Cells.SaveFormat.CSV);
opts.Separator = '\t';
// Copy each worksheet data in text format inside workbook data array
for (int idx = 0; idx < workbook.Worksheets.Count; idx++)
{
// Save the active worksheet into text format
MemoryStream ms = new MemoryStream();
workbook.Worksheets.ActiveSheetIndex = idx;
workbook.Save(ms, opts);
// Save the worksheet data into sheet data array
ms.Position = 0;
byte[] sheetData = ms.ToArray();
// Combine this worksheet data into workbook data array
byte[] combinedArray = new byte[workbookData.Length + sheetData.Length];
Array.Copy(workbookData, 0, combinedArray, 0, workbookData.Length);
Array.Copy(sheetData, 0, combinedArray, workbookData.Length, sheetData.Length);
workbookData = combinedArray;
}
string OutputTextTempFilePath = Path.GetTempFileName();
// Save entire workbook data into file
ZlpIOHelper.WriteAllBytes(OutputTextTempFilePath, workbookData);
string Result = ZlpIOHelper.ReadAllText(OutputTextTempFilePath);
ZlpIOHelper.DeleteFile(OutputTextTempFilePath);
return (Result);