从excel导入到gridview [英] import from excel to gridview

查看:101
本文介绍了从excel导入到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

让我知道如何将数据从excel导入到网格视图.我想单击打开文件对话框的按钮,然后选择要导入到Gridview的excel工作表.

我该怎么办.

在此先感谢...

Hi All,

Let me know how to import data from excel to grid view.I want to click on button where a file dialog box opens,then i use to select excel sheet which is then imported to gridview.

How can i do it.

Thanks in advance...

推荐答案

您的问题有两个部分

1-将excel文件上传到服务器
2-将数据导出到Gridview

适用于:
1-使用简单的文件上传器控件,并在服务器端接收文件流.请记住,您的文件在内存中,不会保存在其他任何地方.

2-导出操作需要源数据和目标控制.在您的情况下,源数据在内存流中,而目标控件是gridview.因此,您需要将上传的文件保存到服务器上的临时位置,然后使用上述示例的路径将其导出到Gridview,或者可以使用Excel interop程序集,但是需要找到一种将内存流转换为Excel的方法.的WorkBook对象.

注意:我无法回忆起,但是excel oledb驱动程序在读取数据方面有一些限制,因为该驱动程序基于前N个行来分析要读取的数据大小.我认为它具有以下内容:
http://social.msdn.microsoft.com/论坛/en-US/adodotnetdataproviders/thread/8ac74201-0371-47d9-b6a9-2993942777aa [ http://www.dreamincode.net/forums/topic/192828 -reading-excel-data-from-specific-cells/ [
There are 2 parts of your question

1- Uploading the excel file to the server
2- exporting the data to Gridview

For:
1- use simple file uploader control and receives the file stream at server end. Remember your file is in memory it is not saved anywhere else.

2- Exporting operation requires source data and target control. In your case source data is in memory stream and target control is gridview. So you need to either save the uploaded file to a temp location on server and then use the path with the above examples to export it to Gridview, or you can use Excel interop assembly but you need to find a way to convert memory stream to Excel''s WorkBook object.

Note: I''m not able to recall but excel oledb driver has some limitation in reading data because the driver analyze the data size to read based on first N number of rows. I think it has something like below:
http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/8ac74201-0371-47d9-b6a9-2993942777aa[^]

So i''ll vote for Excel interop. I found a link which talks about exporting data to xml you can code similar for GridView.
http://www.dreamincode.net/forums/topic/192828-reading-excel-data-from-specific-cells/[^]

Thanks,
Hemant


某些链接可能会对您有所帮助-
http://dotnetguts.blogspot.com/2006/10/import-excel- to-datagrid-aspnet.html [ ^ ]
从GridView导入和导出数据 [
Some links that might help you -
http://dotnetguts.blogspot.com/2006/10/import-excel-to-datagrid-aspnet.html[^]
Import and Export Data from GridView[^]


查看此链接

http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx [ ^ ]
see this link

http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx[^]


这篇关于从excel导入到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆