在Office 2010中导出到Excel [英] Export to Excel in Office 2010
本文介绍了在Office 2010中导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试导出到excel.在Office 2003中,它运行良好.
但是在Office 2007和2010中,其给人的问题是
试图打开"FileName"的文件具有文件扩展名指定的不同格式."
我得到了一种修改注册表值的解决方案,但不能这样做,因为您的应用程序的用户数量非常高.
我用于导出到Excel的代码
Hi,
I am trying to export to excel .In office 2003 it was running fine .
But in Office 2007 and 2010 its giving issue that
"FILE you are trying to open "FileName" is in a different format specified by the file extension."
I got one solution of modifying registry value but can not do that because the number of users for ur application is very high.
Code I am using for Export to Excel
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment; filename=AdminReport.xls")
Response.BufferOutput = True
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.Charset = "UTF-8"
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
tblExcelExport.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
推荐答案
这是我用来导出到excel的代码,我的是datagrid-excel,所以我假设您必须将其更改为使用openfiledialog.我使用Office 2010,效果很好.
Here is the code I use to export to excel, mine is a datagrid-excel, so I''m assuming you will have to change it to use an openfiledialog. I use office 2010 and this works just fine.
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New excel.Application
Try
Dim excelBook As excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As excel.Worksheet = CType(excelBook.Worksheets(1), excel.Worksheet)
xlApp.Visible = True
rowsTotal =
PersonnelDataGridView
PersonnelDataGridView
.RowCount-1 colsTotal =
.RowCount - 1 colsTotal =
这篇关于在Office 2010中导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文