#Excel,ppt,word를 html로 전환
1. 워드를 html 디스플레이로 전환
//========================================================================
// : WordToHtml
/// <summary>
/// Word Html
/// </summary>
/// <param name="wordfilename">word </param>
/*=======================================================================
0001 2008/07/22
=======================================================================*/
public static string WordToHtml(object wordfilename)
{
//
word.Application word = new word.Application();
Type wordtype = word.GetType();
word.Documents docs = word.Documents;
//
Type docstype = docs.GetType();
word.Document doc = (word.Document)docstype.InvokeMember("open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new object[] { wordfilename, true, true });
// ,
Type doctype = doc.GetType();
string wordsavefilename = wordfilename.ToString();
string strsavefilename = wordsavefilename.Substring(0, wordsavefilename.Length - 3) + "html";
object savefilename = (object)strsavefilename;
doctype.InvokeMember("saveas", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
doctype.InvokeMember("close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
// word
wordtype.InvokeMember("quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
return savefilename.ToString();
}
2. PPT를 html 디스플레이로 전환
//========================================================================
// : PPTToHtml
/// <summary>
/// PPT Html
/// </summary>
/// <param name="pptFilename">PPT </param>
/*=======================================================================
0001 2008/07/22
=======================================================================*/
public string PPTToHtml(string pptFilename)
{
// html
string saveFileName = pptFilename + ".html";
Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Core.MsoTriState m1 = new MsoTriState();
Microsoft.Office.Core.MsoTriState m2 = new MsoTriState();
Microsoft.Office.Core.MsoTriState m3 = new MsoTriState();
Microsoft.Office.Interop.PowerPoint.Presentation pp = ppt.Presentations.Open(pptFilename, m1, m2, m3);
pp.SaveAs(saveFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
pp.Close();
//
return saveFileName;
}
3. Excel을 html로 표시
//========================================================================
// : ExcelToHtml
/// <summary>
/// Excel Html
/// </summary>
/// <param name="excelFileName">Excel </param>
/*=======================================================================
0001 2008/07/22
=======================================================================*/
public string ExcelToHtml(string excelFileName)
{
// Excel
Microsoft.Office.Interop.Excel.Application repExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = null;
Microsoft.Office.Interop.Excel.Worksheet worksheet = null;
// ,n.FullPath
workbook = repExcel.Application.Workbooks.Open(excelFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];
string filesavefilename = excelFileName.ToString();
string strsavefilename = filesavefilename.Substring(0, filesavefilename.Length - 3) + "html";
object savefilename = (object)strsavefilename;
object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
//
workbook.SaveAs(savefilename, ofmt, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
object osave = false;
//
workbook.Close(osave, Type.Missing, Type.Missing);
repExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
worksheet = null;
//
GC.Collect();
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;
GC.Collect();
System.Runtime.InteropServices.Marshal.ReleaseComObject(repExcel.Application.Workbooks);
GC.Collect();
System.Runtime.InteropServices.Marshal.ReleaseComObject(repExcel);
repExcel = null;
GC.Collect();
//
System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL");
foreach (System.Diagnostics.Process p in process)
{
if (DateTime.Now.Second - p.StartTime.Second > 0 && DateTime.Now.Second - p.StartTime.Second < 5)
{
p.Kill();
}
}
return savefilename.ToString();
}
이상은 html 파일로 변환하는 방법입니다. 변환에 성공하면 폴더 아래에 대응하는 이미지 폴더와 스타일 파일, 그리고 html 파일이 생성됩니다.이 중 Excel에 여러 개의 sheet이 포함되어 있을 경우 전환된 html에는 여러 개의tab이 포함되어 있으며, 각각의 sheet이 한 페이지로 바뀌려면 코드를 수정해야 한다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다른 사람의 웹사이트 편집: contenteditable 및 designMode그래도 우리가 그렇게 할 수 있다고 생각하는 것은 멋진 일입니다. 제가 강조하고 싶었던 일종의 관련 API가 실제로 몇 개 있기 때문에 오늘 그것을 가져왔습니다. contenteditable는 "true" 값이 할당...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.