excel学习库

excel表格_excel函数公式大全_execl从入门到精通

成功EXCEL转换成html文件

前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="WebApplication1.Excel1.tohtml.test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>EXCEL转换成html文件</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:Button ID="Button1" runat="server" Text="开始转换" onclick="Button1_Click" />
</form>
</body>
</html>

后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using WebApplication1.common;

namespace WebApplication1.Excel1.tohtml
{
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
excel_to.ExcelConvertToHtml(Server.MapPath("../data/test1.xls"), Server.MapPath("../data/test2.html"));
}

}
}

类:
public static void ExcelConvertToHtml(string xlsPath, string htmlPath)
{
try
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = false;
Object o = Missing.Value;

/**/
/// _Workbook xls=app.Workbooks.Open(xlsPath,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);

_Workbook xls = app.Workbooks.Open(xlsPath, o, o, o, o, o, o, o, o, o, o, o, o);
object fileName = htmlPath;
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;//Html

// xls.SaveAs(ref fileName,ref format,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
if (System.IO.File.Exists(fileName.ToString()) == true)
{
System.IO.Directory.Delete(fileName.ToString(), true);
}
xls.SaveAs(fileName, format, o, o, o, o, XlSaveAsAccessMode.xlExclusive, o, o, o, o);
object t = true;
app.Quit();

Process[] myProcesses = Process.GetProcessesByName("EXCEL");
foreach (Process myProcess in myProcesses)
{
myProcess.Kill();
}
}
catch (Exception ex)
{
System.Console.Write(ex.Message);
}
}

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2024年12月    »
1
2345678
9101112131415
16171819202122
23242526272829
3031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
    文章归档
      友情链接