Aspose 를 사용 하여 office 파일 을 Html 파일 로 변환 하고 파일 생 성

3143 단어 officeAspose
Aspose 를 사용 하여 office 파일 을 Html 파일 로 변환 하 는 방법 은 다음 과 같 습 니 다.
        /// 
        /// office     Html
        /// 
        ///    
        ///      
        ///     
        /// 
        public static string FileToHtmlFile(string extFileName, string sourceFile, string desFile)
        {
            if (string.IsNullOrEmpty(sourceFile))
            {
                return "0";//    
            }

            switch (extFileName.ToUpper())
            {
                case "PPT":
                case "PPTX":
                    Aspose.Slides.Presentation ppt = new Aspose.Slides.Presentation(sourceFile);
                    ppt.Save(desFile, Aspose.Slides.Export.SaveFormat.Html);
                    break;
                case "DOC":
                case "DOCX":
                    Aspose.Words.Document doc = new Aspose.Words.Document(sourceFile);
                    doc.Save(desFile, Aspose.Words.SaveFormat.Html);
                    break;
                //case "XLS":
                    //case "XLSX":
                   //    break;
            }
            return "ok";
        }

PPT 파일 이 생 성 된 html 에 인 코딩 인식 오류 가 발생 하여 브 라 우 저 웹 페이지 가 혼 란 스 러 워 집 니 다.
해결 방법 은 다음 과 같다.
                System.IO.StreamReader sr = new System.IO.StreamReader(strFilePath);
                string html = sr.ReadToEnd();
                sr.Close();
                System.IO.StreamWriter sw = new System.IO.StreamWriter(strFilePath, false);
                //System.IO.StreamWriter sw = new System.IO.StreamWriter(strFilePath, false, Encoding.UTF8);
                //    :      ,         
                html = html.Replace("", "");
                //      
                html = html.Replace("Evaluation only", "");
                html = html.Replace("Created with Aspose.Slides for .NET 2.0 14.8.1.0.", "");
                html = html.Replace("Copyright 2004-2014 Aspose Pty Ltd.", "");
                //html = html.Replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2014 Aspose Pty Ltd.", "");
                html = html.Replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2014 Aspose Pty Ltd.", "");
                html = html.Replace("This document was truncated here because it was created using Aspose.Words in Evaluation Mode.", "");
                // < meta http - equiv = "X-UA-Compatible" content = "IE=9" >< meta http - equiv = "Content-Type" content = "text/html; charset=utf-8" />
                sw.Write(html);
                sw.Close();

좋은 웹페이지 즐겨찾기