如何从数据表创建Excel文件并保存到本地文件夹Asp.Net? [英] How Can I Create An Excel File From Data Table And Save In To Local Folder Asp.Net?

查看:53
本文介绍了如何从数据表创建Excel文件并保存到本地文件夹Asp.Net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据表中创建一个excel文件。然后我需要将它保存在我的文件夹中(我需要以编程方式选择文件夹)。



我该怎么做?

I want to create one excel file from my data table. Then i need to save it on my folder (I need to select folder programmatically).

How can i do this ?

推荐答案

DataSet to Excel File Conversion使用ExcelLibrary [ ^ ]



使用上面的链接来获得解决方案。



如果您满意,请标记为答案。



谢谢,

Vipul
DataSet to Excel File Conversion using ExcelLibrary[^]

Use above link to get solution.

Please mark as answer if you are satisfied.

Thanks,
Vipul






我的方式是使用DataTables WriteXml方法。



例如

Hi,

The way I do it is use DataTables WriteXml method.

For e.g.
DataTable dt = new DataTable("Test");
            dt.Columns.Add("Code", typeof(string));
            dt.Columns.Add("Price", typeof(int));

            DataRow dr = dt.NewRow();
            dr["Code"] = "ABC";
            dr["Price"] = 12;

            dt.Rows.Add(dr);

            DataRow dr1 = dt.NewRow();
            dr1["Code"] = "PQR";
            dr1["Price"] = 1;

            dt.Rows.Add(dr1);

            dt.WriteXml("D:/Test.xls");





你可以在这里把你的路径传递给writexml。



问候,

Praneet



You can pass your path to writexml here.

Regards,
Praneet






我认为使用互操作可以更好。这是一个非常好的例子:

使用C#Excel Interop将DataSet导出到Excel中[ ^ ]



希望这会有所帮助。



问候,

Praneet
Hi,

I think using interop can be better. This is a very good example.:
Export DataSet into Excel using C# Excel Interop[^]

Hope this will help.

Regards,
Praneet


这篇关于如何从数据表创建Excel文件并保存到本地文件夹Asp.Net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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