乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何用<em>ASP</em>读取Excel文件-asp 访问excel,aspexcel报表

如何用<em>ASP</em>读取Excel文件-asp 访问excel,aspexcel报表

作者:乔山办公网日期:

返回目录: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关不掉.....

相关阅读

  • -asp连接 excel,aspexcel报表

  • 乔山办公网excel表格制作
  • 假设你的数据是D:1.XLS,工作表是e799bee5baa6e997aee7ad94e78988e69d83366:Sheet1 则连接串:strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:1.xls;Extended Proper
  • <em>asp</em>如何<em>显示excel</em>里的%-as

  • 乔山办公网excel表格制作
  • ASP读取EXCEL有某一列的数据读取不到,显示为空?" src="/uploads/tu/301.jpg" style="width: 400px; height: 267px;" />没懂你的意思,什么叫显示excel里的%,是你的asp在读取提交的excel文件吗?解决同一列
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网