public override DocumentEntity ConvertToHtml(Common.Entities.DocumentEntity _docEntity)
 {
     if (!_docEntity.isConvert && String.IsNullOrEmpty(_docEntity.ConvertError))
     {
         Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(_docEntity.FilePath);
         _docEntity.HtmlData            = new HtmlParseContext();
         _docEntity.HtmlData.PageNumber = xls.Worksheets.Count;
         foreach (Aspose.Cells.Worksheet item in xls.Worksheets)
         {
             Aspose.Cells.HtmlSaveOptions htmlsaveoption = new Aspose.Cells.HtmlSaveOptions(Aspose.Cells.SaveFormat.Html);
             htmlsaveoption.AttachedFilesDirectory = Path.Combine(_docEntity.ResourcesPath, "image");
             htmlsaveoption.HtmlCrossStringType    = Aspose.Cells.HtmlCrossType.Cross;
             using (MemoryStream htmlStream = new MemoryStream())
             {
                 try
                 {
                     xls.Worksheets.ActiveSheetIndex = item.Index;
                     xls.Save(htmlStream, htmlsaveoption);
                     _docEntity.HtmlData.HtmlContent.Add(Encoding.UTF8.GetString(htmlStream.ToArray()));
                     _docEntity.isConvert = true;
                 }
                 catch (Exception e)
                 {
                     _docEntity.isConvert    = false;
                     _docEntity.ConvertError = e.Message;
                 }
             }
         }
     }
     return(_docEntity);
 }
        /// <summary>
        /// Excel 生成 HTML 文件
        /// </summary>
        /// <param name="excelPath">Excel 路径</param>
        /// <param name="htmlPath">Html 路径</param>
        /// <param name="sheetName">表单名称</param>
        public static void ExcelToHtmlFile(string excelPath, string htmlPath, string sheetName = "")
        {
            Aspose.Cells.HtmlSaveOptions htmlSaveOptions = new Aspose.Cells.HtmlSaveOptions(Aspose.Cells.SaveFormat.Html);
            Aspose.Cells.Workbook        workBook        = new Aspose.Cells.Workbook(excelPath);
            if (string.IsNullOrEmpty(sheetName))
            {
                workBook.Save(htmlPath, htmlSaveOptions);
            }
            else
            {
                Aspose.Cells.Workbook  newWorkBook  = new Aspose.Cells.Workbook();
                Aspose.Cells.Worksheet newWorkSheet = newWorkBook.Worksheets[0];
                newWorkSheet.Copy(workBook.Worksheets[sheetName]);
                newWorkBook.Save(htmlPath, htmlSaveOptions);
            }

            string directoryPath = string.Format("{0}/{1}_files", Path.GetDirectoryName(htmlPath), System.IO.Path.GetFileNameWithoutExtension(htmlPath));

            string[] filePathList = Directory.GetFiles(directoryPath, "*.htm");
            foreach (string filePath in filePathList)
            {
                TransformHTMLEncoding(filePath, string.Format("<script>\ndocument.write(\"<div style='color:red;font-size:10pt;font-family:Arial'>Evaluation Only. Created with Aspose.Cells for .NET.Copyright 2003 - 2018 Aspose Pty Ltd.</div>\");\n</script>"));
            }
            TransformHTMLEncoding(htmlPath, string.Format("<frame src=\"{0}_files/tabstrip.htm\" name=\"frTabs\" marginwidth=\"0\" marginheight=\"0\">", Path.GetFileNameWithoutExtension(htmlPath)));
        }
Exemple #3
0
        public static void Main()
        {
            // ExStart:1
            // Load the sample Excel file containing single sheet only
            Workbook wb = new Workbook(sourceDir + "sampleSingleSheet.xlsx");

            // Specify HTML save options
            Aspose.Cells.HtmlSaveOptions options = new Aspose.Cells.HtmlSaveOptions();

            // Set optional settings if required
            options.Encoding                 = System.Text.Encoding.UTF8;
            options.ExportImagesAsBase64     = true;
            options.ExportGridLines          = true;
            options.ExportSimilarBorderStyle = true;
            options.ExportBogusRowData       = true;
            options.ExcludeUnusedStyles      = true;
            options.ExportHiddenWorksheet    = true;

            //Save the workbook in Html format with specified Html Save Options
            wb.Save(outputDir + "outputSampleSingleSheet.htm", options);
            // ExEnd:1
            Console.WriteLine("SetSingleSheetTabNameInHtml executed successfully.");
        }