using System.IO; using System.Text; using System.Web; using GemBox.Spreadsheet; public static class GemBoxSpreadsheetHelper { public static void SaveAsSingleHtml(this ExcelFile ef, string filePath) { StringBuilder singleHtmlFileContent = new StringBuilder(); string htmlTopContent = ""; string htmlBottomContent = ""; int worksheetCount = ef.Worksheets.Count; HtmlSaveOptions saveOption = new HtmlSaveOptions() { SelectionType = SelectionType.ActiveSheet, HtmlType = HtmlType.HtmlTable }; singleHtmlFileContent.Append(htmlTopContent); for (int i = 0; i < worksheetCount; i++) { ef.Worksheets.ActiveWorksheet = ef.Worksheets[i]; using (var stream = new MemoryStream()) { ef.Save(stream, saveOption); singleHtmlFileContent.Append(saveOption.Encoding.GetString(stream.ToArray())); } } singleHtmlFileContent.Append(htmlBottomContent); File.WriteAllText(filePath, singleHtmlFileContent.ToString(), saveOption.Encoding); } public static void SaveAsSingleHtml(this ExcelFile ef, HttpResponse response) { StringBuilder singleHtmlFileContent = new StringBuilder(); string htmlTopContent = ""; string htmlBottomContent = ""; int worksheetCount = ef.Worksheets.Count; HtmlSaveOptions saveOption = new HtmlSaveOptions() { SelectionType = SelectionType.ActiveSheet, HtmlType = HtmlType.HtmlTable }; singleHtmlFileContent.Append(htmlTopContent); for (int i = 0; i < worksheetCount; i++) { ef.Worksheets.ActiveWorksheet = ef.Worksheets[i]; using (var stream = new MemoryStream()) { ef.Save(stream, saveOption); singleHtmlFileContent.Append(saveOption.Encoding.GetString(stream.ToArray())); } } singleHtmlFileContent.Append(htmlBottomContent); response.Write(singleHtmlFileContent.ToString()); response.Flush(); response.Close(); response.End(); } }