21 个解决方案
#1
excel na li lai ?
#2
function CellAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = Project1.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = Project1.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = Project1.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
这是客户端的
要把服务器IP放到信任站点中
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = Project1.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = Project1.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = Project1.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
这是客户端的
要把服务器IP放到信任站点中
#3
public static void ExportToExcel(System.Web.UI.Control control, string ExcelFileName)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "GB2312";
context.Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(ExcelFileName,System.Text.Encoding.UTF8) + ".xls");
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
context.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
control.RenderControl(oHtmlTextWriter);
string charset ="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">";
context.Response.Write(charset+oStringWriter.ToString());
context.Response.End();
}
#4
这是我服务器端生成Excel的代码,服务器端有个Excel模版,
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook WorkBook = excel.Workbooks.Open(@"C:\ExcelTemplate.xlt", Missing.Value, false, Missing.Value, null, null, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet sheet = (Excel.Worksheet)WorkBook.Sheets["Sheet1"];
sheet.Cells[1, 1] = "test";
//WorkBook.SaveAs("c:\\test.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
WorkBook.Close(false, Type.Missing, Type.Missing);
excel.Quit();
我想不保存WorkBook,直接转成流供客户端下载,怎么实现啊?
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook WorkBook = excel.Workbooks.Open(@"C:\ExcelTemplate.xlt", Missing.Value, false, Missing.Value, null, null, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet sheet = (Excel.Worksheet)WorkBook.Sheets["Sheet1"];
sheet.Cells[1, 1] = "test";
//WorkBook.SaveAs("c:\\test.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
WorkBook.Close(false, Type.Missing, Type.Missing);
excel.Quit();
我想不保存WorkBook,直接转成流供客户端下载,怎么实现啊?
#5
我想读取模版修改后,实现直接下载
#6
参考这个方法后面的几句代码
public void OutputExcel(DataView dv, string str)
{
//
// TODO: 在此处添加构造函数逻辑
//
//dv为要输出到Excel的数据,str为标题名称
GC.Collect();
Application excel;// = new Application();
int rowIndex = 4;
int colIndex = 1;
_Workbook xBk;
_Worksheet xSt;
excel = new ApplicationClass();
xBk = excel.Workbooks.Add(true);
xSt = (_Worksheet)xBk.ActiveSheet;
//
//取得标题
//
foreach (DataColumn col in dv.Table.Columns)
{
colIndex++;
excel.Cells[4, colIndex] = col.ColumnName;
xSt.get_Range(excel.Cells[4, colIndex], excel.Cells[4, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置标题格式为居中对齐
}
//
//取得表格中的数据
//
foreach (DataRowView row in dv)
{
rowIndex++;
colIndex = 1;
foreach (DataColumn col in dv.Table.Columns)
{
colIndex++;
if (col.DataType == System.Type.GetType("System.DateTime"))
{
excel.Cells[rowIndex, colIndex] = (Convert.ToDateTime(row[col.ColumnName].ToString())).ToString("yyyy-MM-dd");
xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置日期型的字段格式为居中对齐
}
else
if (col.DataType == System.Type.GetType("System.String"))
{
excel.Cells[rowIndex, colIndex] = "'" + row[col.ColumnName].ToString();
xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置字符型的字段格式为居中对齐
}
else
{
excel.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString();
}
}
}
//
//加载一个合计行
//
int rowSum = rowIndex + 1;
int colSum = 2;
excel.Cells[rowSum, 2] = "合计";
xSt.get_Range(excel.Cells[rowSum, 2], excel.Cells[rowSum, 2]).HorizontalAlignment = XlHAlign.xlHAlignCenter;
//
//设置选中的部分的颜色
//
xSt.get_Range(excel.Cells[rowSum, colSum], excel.Cells[rowSum, colIndex]).Select();
xSt.get_Range(excel.Cells[rowSum, colSum], excel.Cells[rowSum, colIndex]).Interior.ColorIndex = 19;//设置为浅黄色,共计有56种
//
//取得整个报表的标题
//
excel.Cells[2, 2] = str;
//
//设置整个报表的标题格式
//
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Bold = true;
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Size = 22;
//
//设置报表表格为最适应宽度
//
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Select();
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Columns.AutoFit();
//
//设置整个报表的标题为跨列居中
//
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, colIndex]).Select();
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, colIndex]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection;
//
//绘制边框
//
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Borders.LineStyle = 1;
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, 2]).Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;//设置左边线加粗
xSt.get_Range(excel.Cells[4, 2], excel.Cells[4, colIndex]).Borders[XlBordersIndex.xlEdgeTop].Weight = XlBorderWeight.xlThick;//设置上边线加粗
xSt.get_Range(excel.Cells[4, colIndex], excel.Cells[rowSum, colIndex]).Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;//设置右边线加粗
xSt.get_Range(excel.Cells[rowSum, 2], excel.Cells[rowSum, colIndex]).Borders[XlBordersIndex.xlEdgeBottom].Weight = XlBorderWeight.xlThick;//设置下边线加粗
//
//显示效果
//
excel.Visible = true;
//xSt.Export(Server.MapPath(".")+"\\"+this.xlfile.Text+".xls",SheetExportActionEnum.ssExportActionNone,Microsoft.Office.Interop.OWC.SheetExportFormat.ssExportHTML);
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
//ds = null;
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
GC.Collect();
string path = Server.MapPath(this.xlfile.Text + ".xls");
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
}
#7
在保存文件时直接保存到流里面,然后输出流
#8
楼上的
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
这句不是会在服务器端生成一个xls文件吗?
我想不保存,怎么操作啊
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
这句不是会在服务器端生成一个xls文件吗?
我想不保存,怎么操作啊
#9
楼上已经写了
#10
www.codeproject.com/asp/dynamicexcel.asp
#11
来看看
#12
http://www.shenjk.com/CateContent.asp?CID=12&ID=159 导出Excel数据的四种方法
#13
deansroom的方法也会在服务器端生成一个xls文件阿
#14
<html>
<head>
<title>将数据导出为Execl文件 JavaScript</title>
<script language="javascript">
function SaveToExcel(tblData)
{
if(typeof(objExecl)!="object")
{
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid='clsid:0002E510-0000-0000-C000-000000000046' id='objExecl' VIEWASTEXT></OBJECT>");
}
objExecl.DataType = "HTMLData";
objExecl.HTMLData =tblData.outerHTML;
try
{
objExecl.ActiveSheet.Export("OutToExcel.xls",0);
alert("保存成功");
}
catch(e)
{
alert(e.description);
}
}
</script>
</head>
<body>
<table id="aa">
<tr>
<td>title</td>
<td>id</td>
</tr>
<tr>
<td>aaaa</td>
<td>1</td>
</tr>
</table>
<input type="button" value="导出EXCEL" LANGUAGE="javascript" onclick="SaveToExcel(aa);">
</body>
</html>
是不是要这样的
<head>
<title>将数据导出为Execl文件 JavaScript</title>
<script language="javascript">
function SaveToExcel(tblData)
{
if(typeof(objExecl)!="object")
{
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid='clsid:0002E510-0000-0000-C000-000000000046' id='objExecl' VIEWASTEXT></OBJECT>");
}
objExecl.DataType = "HTMLData";
objExecl.HTMLData =tblData.outerHTML;
try
{
objExecl.ActiveSheet.Export("OutToExcel.xls",0);
alert("保存成功");
}
catch(e)
{
alert(e.description);
}
}
</script>
</head>
<body>
<table id="aa">
<tr>
<td>title</td>
<td>id</td>
</tr>
<tr>
<td>aaaa</td>
<td>1</td>
</tr>
</table>
<input type="button" value="导出EXCEL" LANGUAGE="javascript" onclick="SaveToExcel(aa);">
</body>
</html>
是不是要这样的
#15
有时候试试保存完某时刻删除,也许是更好的方案,因为多次下载时不需要多次生成,减少服务器压力
#16
在服务器端不需要生成execl文件啊,用脚本就行了
上面的已经贴出来了
上面的已经贴出来了
#17
http://www.ebookit.cn/177.html
#18
学习了。。
#19
鼎
#20
有时候试试保存完某时刻删除,也许是更好的方案,因为多次下载时不需要多次生成,减少服务器压力
....................................................................
但如果服务器端万一无写权限呢?
....................................................................
但如果服务器端万一无写权限呢?
#21
这个要做
#1
excel na li lai ?
#2
function CellAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = Project1.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = Project1.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = Project1.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
这是客户端的
要把服务器IP放到信任站点中
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = Project1.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = Project1.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = Project1.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
这是客户端的
要把服务器IP放到信任站点中
#3
public static void ExportToExcel(System.Web.UI.Control control, string ExcelFileName)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "GB2312";
context.Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(ExcelFileName,System.Text.Encoding.UTF8) + ".xls");
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
context.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
control.RenderControl(oHtmlTextWriter);
string charset ="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">";
context.Response.Write(charset+oStringWriter.ToString());
context.Response.End();
}
#4
这是我服务器端生成Excel的代码,服务器端有个Excel模版,
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook WorkBook = excel.Workbooks.Open(@"C:\ExcelTemplate.xlt", Missing.Value, false, Missing.Value, null, null, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet sheet = (Excel.Worksheet)WorkBook.Sheets["Sheet1"];
sheet.Cells[1, 1] = "test";
//WorkBook.SaveAs("c:\\test.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
WorkBook.Close(false, Type.Missing, Type.Missing);
excel.Quit();
我想不保存WorkBook,直接转成流供客户端下载,怎么实现啊?
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook WorkBook = excel.Workbooks.Open(@"C:\ExcelTemplate.xlt", Missing.Value, false, Missing.Value, null, null, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet sheet = (Excel.Worksheet)WorkBook.Sheets["Sheet1"];
sheet.Cells[1, 1] = "test";
//WorkBook.SaveAs("c:\\test.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
WorkBook.Close(false, Type.Missing, Type.Missing);
excel.Quit();
我想不保存WorkBook,直接转成流供客户端下载,怎么实现啊?
#5
我想读取模版修改后,实现直接下载
#6
参考这个方法后面的几句代码
public void OutputExcel(DataView dv, string str)
{
//
// TODO: 在此处添加构造函数逻辑
//
//dv为要输出到Excel的数据,str为标题名称
GC.Collect();
Application excel;// = new Application();
int rowIndex = 4;
int colIndex = 1;
_Workbook xBk;
_Worksheet xSt;
excel = new ApplicationClass();
xBk = excel.Workbooks.Add(true);
xSt = (_Worksheet)xBk.ActiveSheet;
//
//取得标题
//
foreach (DataColumn col in dv.Table.Columns)
{
colIndex++;
excel.Cells[4, colIndex] = col.ColumnName;
xSt.get_Range(excel.Cells[4, colIndex], excel.Cells[4, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置标题格式为居中对齐
}
//
//取得表格中的数据
//
foreach (DataRowView row in dv)
{
rowIndex++;
colIndex = 1;
foreach (DataColumn col in dv.Table.Columns)
{
colIndex++;
if (col.DataType == System.Type.GetType("System.DateTime"))
{
excel.Cells[rowIndex, colIndex] = (Convert.ToDateTime(row[col.ColumnName].ToString())).ToString("yyyy-MM-dd");
xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置日期型的字段格式为居中对齐
}
else
if (col.DataType == System.Type.GetType("System.String"))
{
excel.Cells[rowIndex, colIndex] = "'" + row[col.ColumnName].ToString();
xSt.get_Range(excel.Cells[rowIndex, colIndex], excel.Cells[rowIndex, colIndex]).HorizontalAlignment = XlVAlign.xlVAlignCenter;//设置字符型的字段格式为居中对齐
}
else
{
excel.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString();
}
}
}
//
//加载一个合计行
//
int rowSum = rowIndex + 1;
int colSum = 2;
excel.Cells[rowSum, 2] = "合计";
xSt.get_Range(excel.Cells[rowSum, 2], excel.Cells[rowSum, 2]).HorizontalAlignment = XlHAlign.xlHAlignCenter;
//
//设置选中的部分的颜色
//
xSt.get_Range(excel.Cells[rowSum, colSum], excel.Cells[rowSum, colIndex]).Select();
xSt.get_Range(excel.Cells[rowSum, colSum], excel.Cells[rowSum, colIndex]).Interior.ColorIndex = 19;//设置为浅黄色,共计有56种
//
//取得整个报表的标题
//
excel.Cells[2, 2] = str;
//
//设置整个报表的标题格式
//
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Bold = true;
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Size = 22;
//
//设置报表表格为最适应宽度
//
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Select();
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Columns.AutoFit();
//
//设置整个报表的标题为跨列居中
//
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, colIndex]).Select();
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, colIndex]).HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection;
//
//绘制边框
//
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, colIndex]).Borders.LineStyle = 1;
xSt.get_Range(excel.Cells[4, 2], excel.Cells[rowSum, 2]).Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;//设置左边线加粗
xSt.get_Range(excel.Cells[4, 2], excel.Cells[4, colIndex]).Borders[XlBordersIndex.xlEdgeTop].Weight = XlBorderWeight.xlThick;//设置上边线加粗
xSt.get_Range(excel.Cells[4, colIndex], excel.Cells[rowSum, colIndex]).Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;//设置右边线加粗
xSt.get_Range(excel.Cells[rowSum, 2], excel.Cells[rowSum, colIndex]).Borders[XlBordersIndex.xlEdgeBottom].Weight = XlBorderWeight.xlThick;//设置下边线加粗
//
//显示效果
//
excel.Visible = true;
//xSt.Export(Server.MapPath(".")+"\\"+this.xlfile.Text+".xls",SheetExportActionEnum.ssExportActionNone,Microsoft.Office.Interop.OWC.SheetExportFormat.ssExportHTML);
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
//ds = null;
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
GC.Collect();
string path = Server.MapPath(this.xlfile.Text + ".xls");
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
}
#7
在保存文件时直接保存到流里面,然后输出流
#8
楼上的
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
这句不是会在服务器端生成一个xls文件吗?
我想不保存,怎么操作啊
xBk.SaveCopyAs(Server.MapPath(".") + "\\" + this.xlfile.Text + ".xls");
这句不是会在服务器端生成一个xls文件吗?
我想不保存,怎么操作啊
#9
楼上已经写了
#10
www.codeproject.com/asp/dynamicexcel.asp
#11
来看看
#12
http://www.shenjk.com/CateContent.asp?CID=12&ID=159 导出Excel数据的四种方法
#13
deansroom的方法也会在服务器端生成一个xls文件阿
#14
<html>
<head>
<title>将数据导出为Execl文件 JavaScript</title>
<script language="javascript">
function SaveToExcel(tblData)
{
if(typeof(objExecl)!="object")
{
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid='clsid:0002E510-0000-0000-C000-000000000046' id='objExecl' VIEWASTEXT></OBJECT>");
}
objExecl.DataType = "HTMLData";
objExecl.HTMLData =tblData.outerHTML;
try
{
objExecl.ActiveSheet.Export("OutToExcel.xls",0);
alert("保存成功");
}
catch(e)
{
alert(e.description);
}
}
</script>
</head>
<body>
<table id="aa">
<tr>
<td>title</td>
<td>id</td>
</tr>
<tr>
<td>aaaa</td>
<td>1</td>
</tr>
</table>
<input type="button" value="导出EXCEL" LANGUAGE="javascript" onclick="SaveToExcel(aa);">
</body>
</html>
是不是要这样的
<head>
<title>将数据导出为Execl文件 JavaScript</title>
<script language="javascript">
function SaveToExcel(tblData)
{
if(typeof(objExecl)!="object")
{
document.body.insertAdjacentHTML("afterBegin","<OBJECT style='display:none' classid='clsid:0002E510-0000-0000-C000-000000000046' id='objExecl' VIEWASTEXT></OBJECT>");
}
objExecl.DataType = "HTMLData";
objExecl.HTMLData =tblData.outerHTML;
try
{
objExecl.ActiveSheet.Export("OutToExcel.xls",0);
alert("保存成功");
}
catch(e)
{
alert(e.description);
}
}
</script>
</head>
<body>
<table id="aa">
<tr>
<td>title</td>
<td>id</td>
</tr>
<tr>
<td>aaaa</td>
<td>1</td>
</tr>
</table>
<input type="button" value="导出EXCEL" LANGUAGE="javascript" onclick="SaveToExcel(aa);">
</body>
</html>
是不是要这样的
#15
有时候试试保存完某时刻删除,也许是更好的方案,因为多次下载时不需要多次生成,减少服务器压力
#16
在服务器端不需要生成execl文件啊,用脚本就行了
上面的已经贴出来了
上面的已经贴出来了
#17
http://www.ebookit.cn/177.html
#18
学习了。。
#19
鼎
#20
有时候试试保存完某时刻删除,也许是更好的方案,因为多次下载时不需要多次生成,减少服务器压力
....................................................................
但如果服务器端万一无写权限呢?
....................................................................
但如果服务器端万一无写权限呢?
#21
这个要做