请问:Excel转换为html时,如何只将选定区域的内容转换过去?
大家好,我现在在做将word和excel转换为html,直接在网页显示的功能。遇到以下几个问题:
1、excel转为html时,如何只将选定区域的内容转换为html。现在是将整个workbook转成html,转完后,原excel里的空白单元格也一并转过来了,这样就造成页面上表格在最左边,右边有很大一块空白区域。
2、将excel和word转为html时,转完后的内容都居左,怎样才能居中哪?
谢谢 --------------------编程问答-------------------- 不懂
友情帮顶吧 --------------------编程问答-------------------- 我是用的com组件,代码如下:
word->html:
Microsoft.Office.Interop.Word.ApplicationClass myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Type myWordType = myWordApp.GetType();
Microsoft.Office.Interop.Word.Documents myDocs = myWordApp.Documents;
try
{
// 打开文件
Type myDocsType = myDocs.GetType();
object objFileName = strFile;
Microsoft.Office.Interop.Word.Document myDoc = (Microsoft.Office.Interop.Word.Document)myDocsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, myDocs, new Object[] { objFileName, true, true });
// 转换格式,另存为
Type myDocType = myDoc.GetType();
object objSaveFileName = "c:\\" + strFileName + ".html";
myDocType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, myDoc,
new object[] { objSaveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML }); // 退出 Word
myWordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, myWordApp, null);
//Response.ContentType = "Application/doc";
//string FilePath = MapPath("会议纪要-40.html");
//Response.WriteFile(FilePath);
//Response.End();
}
catch
{
}
excel->html:
object objMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.ApplicationClass myExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook myExcelWb = null;
myExcelWb = myExcelApp.Application.Workbooks.Open(strFile, objMissing, objMissing, objMissing,objMissing,objMissing,
objMissing,objMissing,objMissing,objMissing,objMissing,objMissing,objMissing,objMissing,objMissing);
object objSaveFileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
myExcelWb.SaveAs("c:\\" + strFileName + ".html", objSaveFileFormat, objMissing, objMissing, objMissing, objMissing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
objMissing, objMissing,objMissing,objMissing,objMissing);
object objSave = false;
myExcelWb.Close(objSave, objMissing, objMissing); --------------------编程问答-------------------- 帮你顶一下 --------------------编程问答-------------------- 有没有人知道阿? --------------------编程问答-------------------- 帖子沉掉了
补充:.NET技术 , ASP.NET