作者:乔山办公网日期:
返回目录:excel表格制作
using System;
using Excel;
namespace ExcelExample
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ExcelClass
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Excel.Application excelApp = new Excel.ApplicationClass(); // Creates a new Excel Application
excelApp.Visible = false; // Makes Excel visible to the user.
// The following line adds a new workbook
Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
// The following code opens an existing workbook
string workbookPath = "c:/SomeWorkBook.xls"; // Add your own path here
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
false, 0, true, false, false);
// The following gets the Worksheets collection
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
// The following gets Sheet1 for editing
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
// The following gets cell A1 for editing
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");
// The following sets cell A1's value to "Hi There"
excelCell.Value2 = "Hi There";
}
}
Dim Conn,Driver,DBPath,Rs
'建立Excel的百Connection对象
Set Conn = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath( "test.xls" )
'调用Open方法打开数据度库
Conn.Open Driver & DBPath
'设置DSN连接方式
'Conn.Open "Dsn=test"
'注意问 表名一定要按照答 "[表名$]" 格式书写版
Sql="Select * From [Sheet1$] where 序号=0"
Set Rs=Conn.Execute(Sql)
IF Rs.Eof And Rs.Bof Then
Response.write "数据未找到!权!"
Else
Do While Not Rs.EOF
Response.write Rs("书名")
Rs.MoveNext
Loop
End IF
<%
if request.querystring("action")="toExcel" then
Response.ContentType="application/vnd.ms-excel"
Response.AddHeader "content-disposition","attachment;filename=aaa.xls"
end if
%>
<html>
<body>
<table name="data" id="data" width="100%" height="25%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="50%" align="center" bgcolor="#FFFFCC"> <strong>职务 </strong> </td>
<td width="50%" align="center" bgcolor="#FFFFCC"> <strong>职级 </strong> </td>
</tr>
</table>
<input type="button" name="out_excel" onClick="location.href='?action=toExcel'" value="导出到7a64e78988e69d83365excel">
</body>
</html>
调用excel有个问题,提醒下你,我在网上找了很多,还是没解决办法/服务器上会出现很多进程excel.exe关不掉.....