如何使用客户端脚本读取客户端的excel文件内容,直接分别显示在不同的textbox中? 使用owc,请高手给出例子,谢谢!使用.net(c#) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码:<input type="hidden" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint"> <input type="hidden" name="out_excel" onclick="AutomateExcel();" value="导出到excel" class="notPrint"> <title>浏览器表格导出到Excel代码</title><input type="button" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint"> <input type="button" name="out_word1" onclick="javascript:AutomateExcel() " value="导出到excel" class="notPrint"> <table id="data" width="200" border="1"> <tr> <td>11</td> <td>11</td> </tr> <tr> <td>22</td> <td>22</td> </tr> <tr> <td>33</td> <td>33</td> </tr> <tr> <td>44 </td> <td>44</td> </tr></table><SCRIPT LANGUAGE="JavaScript"><!--function AutomateExcel() {// Start Excel and get Application object.var oXL = new ActiveXObject("Excel.Application"); // Get a new workbook.var oWB = oXL.Workbooks.Add();var oSheet = oWB.ActiveSheet;var table = document.all.data; var hang = table.rows.length;var lie = table.rows(0).cells.length; // Add table headers going cell by cell.for (i=0;i<hang;i++){for (j=0;j<lie;j++){oSheet.Cells(i+1,j+1).Value = table.rows(i).cells(j).innerText;}}oXL.Visible = true;oXL.UserControl = true;}//--></SCRIPT> private void Button1_Click(object sender, System.EventArgs e){ //写入Excel的方法: //定义需要参数。 string SourceFile="Data.XLS"; //源文件名称。 string TemplatePath=Server.MapPath("ExcelTemplate"); //存放源文件的文件夹路径。 string DownloadPath=Server.MapPath("ExcelDownload"); //副本的文件夹路径。 //副本的文件名。 string TempFileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".XLS"; object missing = System.Reflection.Missing.Value; Excel.Application myExcel=new Excel.Application(); //打开新文件 myExcel.Application.Workbooks.Open(TemplatePath+"\\"+SourceFile,missing,missing,missing,missing, missing,missing,missing,missing,missing,missing, missing,missing); Excel.Workbook myBook=myExcel.Workbooks[1]; Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[2]; string DownloadFilePath=DownloadPath+"\\"+TempFileName; int i=0; while (i<=10) { myExcel.Cells[4+i,2]=i.ToString(); myExcel.Cells[4+i,3]=i.ToString(); myExcel.Cells[4+i,4]=i.ToString(); myExcel.Cells[4+i,5]=i.ToString(); myExcel.Cells[4+i,6]=i.ToString(); i++; } myBook.Saved=true; //myBook.SaveAs(DownloadFilePath,missing,"","",false,false,Excel.XlSaveAsAccessMode.xlNoChange,1,false,missing,missing); myBook.PrintPreview(0); //myBook.PrintOut(missing,missing,missing,missing,missing,missing,missing,missing); myBook.Close(false, null,null); myExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel); myBook = null; myExcel = null; GC.Collect(); //Response.Redirect("ExcelDownload//"+TempFileName); //下载文件} 不是很明白,只有通过ActiveX来做吧. 是从excel中导出吧,我也正需要这代码,谁有分享一下吧 不理解 求解释。。。 功力不够想不出来。。(winform) 跪求无刷新gridview 或者datelist 无刷新分页 如何让outlook和.exe件在server上始终运行,无人职守呢? 如何在另外一台电脑上重新打开项目 创建RadioButtonlist,怎么写??? 事件调用请教。。。。 关于SqlDatereader问题 关于多条筛选条件的问题 有关于WebClient.UploadFile上传到远程服务器,文件无法保存,本地网络可以 解析字符串为json的建值 asp.net(c#)怎么清除已经生成的cookie啊? 对话框问题
<input type="hidden" name="out_excel" onclick="AutomateExcel();" value="导出到excel" class="notPrint"> <title>浏览器表格导出到Excel代码</title>
<input type="button" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<input type="button" name="out_word1" onclick="javascript:AutomateExcel() " value="导出到excel" class="notPrint">
<table id="data" width="200" border="1">
<tr>
<td>11</td>
<td>11</td>
</tr>
<tr>
<td>22</td>
<td>22</td>
</tr>
<tr>
<td>33</td>
<td>33</td>
</tr>
<tr>
<td>44 </td>
<td>44</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var table = document.all.data;
var hang = table.rows.length;var lie = table.rows(0).cells.length; // Add table headers going cell by cell.
for (i=0;i<hang;i++)
{
for (j=0;j<lie;j++)
{
oSheet.Cells(i+1,j+1).Value = table.rows(i).cells(j).innerText;
}}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>
{
//写入Excel的方法:
//定义需要参数。
string SourceFile="Data.XLS"; //源文件名称。
string TemplatePath=Server.MapPath("ExcelTemplate"); //存放源文件的文件夹路径。
string DownloadPath=Server.MapPath("ExcelDownload"); //副本的文件夹路径。
//副本的文件名。
string TempFileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".XLS";
object missing = System.Reflection.Missing.Value;
Excel.Application myExcel=new Excel.Application();
//打开新文件
myExcel.Application.Workbooks.Open(TemplatePath+"\\"+SourceFile,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing, missing,missing);
Excel.Workbook myBook=myExcel.Workbooks[1];
Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[2];
string DownloadFilePath=DownloadPath+"\\"+TempFileName;
int i=0;
while (i<=10)
{
myExcel.Cells[4+i,2]=i.ToString();
myExcel.Cells[4+i,3]=i.ToString();
myExcel.Cells[4+i,4]=i.ToString();
myExcel.Cells[4+i,5]=i.ToString();
myExcel.Cells[4+i,6]=i.ToString();
i++;
}
myBook.Saved=true;
//myBook.SaveAs(DownloadFilePath,missing,"","",false,false,Excel.XlSaveAsAccessMode.xlNoChange,1,false,missing,missing);
myBook.PrintPreview(0);
//myBook.PrintOut(missing,missing,missing,missing,missing,missing,missing,missing);
myBook.Close(false, null,null);
myExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
myBook = null;
myExcel = null;
GC.Collect();
//Response.Redirect("ExcelDownload//"+TempFileName); //下载文件
}