string path=this.Request.Url.ToString();
string pathsave="D:\\test\\excel\\report.xls";
int i=path.LastIndexOf('/');
path=path.Substring(0,i);
path+="\\excel\\report.xls";
path=path.Replace('/','\\');
Excel.Application ExcelApp=new Excel.ApplicationClass();
Excel.Workbook ExcelWorkBook=ExcelApp.Application.Workbooks.Add(true);
Excel.Worksheet ExcelWorkSheet=(Excel.Worksheet)ExcelWorkBook.Worksheets[1];
ExcelApp.Cells[1,5]="15";
ExcelWorkSheet.get_Range(ExcelWorkSheet.Cells[3,3],ExcelWorkSheet.Cells[6,6]).Value="hello";
ExcelWorkBook.SaveCopyAs(pathsave);
ExcelWorkSheet=null;
ExcelWorkBook.Close(false,null,null);
ExcelApp.Quit();
System.GC.Collection();
string pathsave="D:\\test\\excel\\report.xls";
int i=path.LastIndexOf('/');
path=path.Substring(0,i);
path+="\\excel\\report.xls";
path=path.Replace('/','\\');
Excel.Application ExcelApp=new Excel.ApplicationClass();
Excel.Workbook ExcelWorkBook=ExcelApp.Application.Workbooks.Add(true);
Excel.Worksheet ExcelWorkSheet=(Excel.Worksheet)ExcelWorkBook.Worksheets[1];
ExcelApp.Cells[1,5]="15";
ExcelWorkSheet.get_Range(ExcelWorkSheet.Cells[3,3],ExcelWorkSheet.Cells[6,6]).Value="hello";
ExcelWorkBook.SaveCopyAs(pathsave);
ExcelWorkSheet=null;
ExcelWorkBook.Close(false,null,null);
ExcelApp.Quit();
System.GC.Collection();
需要 using 什么?
我不贴,只收分:)
C#---hhfgh /t sdfsd /t fgdf /n
vb---"sdfsdhfk"+vbTab+vbNewline保存到一个文件中,扩展名为xls
第二种方法不能用response.redirect,并不是你的方法错,而是微软的bug。只能改变一下方法,例如用<meta>或者客户端的javascript来重定向。不过我的实际经验是,服务器端生成Excel的时候经常非法操作,结果非常不稳定。这对于一个系统来说是致命的。
还有第三种方法,就是在客户端生成Excel。这个是我目前采用的方法,比较稳定,速度也没有问题。你可以尝试一下。需要注意的是,客户端要把ie的ActiveX的设置修改一下。
“还有第三种方法,就是在客户端生成Excel。这个是我目前采用的方法,比较稳定,速度也没有问题。你可以尝试一下。需要注意的是,客户端要把ie的ActiveX的设置修改一下。“
怎么做呀!!!
请指点!!!
[email protected]
[email protected]
[email protected].
[email protected]
或
[email protected]可以给分的~~~
[email protected]
[email protected]
谢谢
[email protected]
老大,我以前曾经下载了一个VB做的.dll,但运行时总是报错(不能创建ActiveX).
但在bata2 上却不出错.
能否指点一下,非常感谢!
能发一份给我吗?
'********************************************
'* *
'* 类名: ClassToExcel *
'* 功能: 用于把数据转存为EXCEL文件 *
'* 作者: lql 2001.10.24 *
'* *
'********************************************
Public Class ClassToExcel Public Sub New() End Sub Public Function zSaveToExcel(ByVal strCn As String, ByVal strSql As String, ByVal strPath As String) As String
'==============得到一个不存在的文件名============
Dim r As Boolean
Dim sf, spath, sfx, sFilename As String
Dim i As Integer i = 0
sfx = ".xls"
spath = strPath
sf = "0" '判断文件是否存在
r = System.IO.File.Exists(spath + sf + sfx) '如果文件存在, 试图删除; 不能删除则换一文件名, 直至文件可以被删除或文件不存在
While r
Try
System.IO.File.Delete(spath + sf + sfx)
MsgBox("deleted file!")
r = False
Catch
'Err.Number = 57
i = i + 1
sf = i.ToString().Trim()
r = System.IO.File.Exists(spath + sf + sfx)
End Try
End While sFilename = spath + sf + sfx '============转换为Excel文件===================
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1) 'Create the QueryTable
Dim oQryTable As Object
oQryTable = oSheet.QueryTables.Add( _
"OLEDB;" & strCn & ";", oSheet.Range("A1"), strSql)
oQryTable.RefreshStyle = 1
oQryTable.Refresh(False) 'Save the Workbook and Quit Excel
oBook.SaveAs(sFilename)
oExcel.Quit()
oSheet = Nothing
oBook = Nothing
oExcel = Nothing zSaveToExcel = sf + sfx
End Function
End Class
老大,能发一份给我吗?
[email protected]
你如果需要存excel文件,就直接用代码来进行,还不需要注册dll,并不麻烦。关于客户端生成excel的问题,设置的方法如下:
1.启动Internet Explorer
2.如果是IE 5.0以上,选择工具菜单;如果是IE 4.0,选择查看菜单。然后点击Internet选项
3.单击“安全”选项卡
4.点“自定义级别”按钮
5.将“对没有标记为安全的Active X控件进行初始化和脚本运行”从“禁用”状态改为“提示”(会提示用户是否运行)或者“启用”(不会提示)
首先感谢老大,但按你的方法我还是没搞定,现在只盼望你能尽快将代码贴出来,万分感激!
如果能发一份给我那就更好了.
[email protected]
[email protected]
[email protected]
先谢了!
先谢了
送分!!!!
[email protected]
对了,conanbos(特兰克斯)和walkingpoison(walkingpoison):
你们可不要忘了帮助我一下,我的信箱是 [email protected].给我发一份吧.
能发一份给我吗?现在的项目太需要它了,谢谢!
[email protected]
可不可以给我也发一个?
我现在很需要这个东西,非常感谢!
[email protected]
可不可以给我也发一个,我现在很需要这个东西,非常感谢!
[email protected]
请顺手多填一个Email
[email protected]
谢谢。
http://conanbos.topcities.com/excel.txt
你可能漏掉了一句
xlsApp.Visible=true
如果没有这一句,只会启动Excel进程,而不显示。
不过如果需要更加详细一点的参考,我可以给你们发送我的代码。
发送的时候也给我一份吧,先谢谢了
[email protected]
我也想要啊,能给我一份吗?
谢谢
我也想要啊,能给我一份吗?
谢谢
[email protected]
[email protected]
阿明