我想在C#中使用来自NuGet的excel DLL将数据集导出到excel表我不想使用microsoft.office.interop.excel;我想只使用excel;请帮忙.. [英] I want to export dataset to excel sheet using excel DLL from NuGet in C# I don't want to use microsoft.office.interop.excel; I want to use only using excel; please help..

查看:211
本文介绍了我想在C#中使用来自NuGet的excel DLL将数据集导出到excel表我不想使用microsoft.office.interop.excel;我想只使用excel;请帮忙..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人帮我,我想在c#中使用exget dll将数据集导出到excel表格中。我不想使用Microsoft.Office.Interop.Excel;我想用Excel只用

;请帮忙。



我尝试了什么:



这是我的数据集。这个数据集我想在excel下载。



使用Excel;

string SqlCommand;

DataSet dsLoadAllTabsDetails;

var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings [LocalConnectionString]。ToString();



List< viewdatamodelapplication> objAPPLI = new list< viewdatamodelapplication>();

using(var conn = new SqlConnection(connectionString))

{

SqlCommand =EXEC USP_Get_AllTabsDetails'+ partId +';

SqlDataAdapter adapter = new SqlDataAdapter(SqlCommand,conn);

dsLoadAllTabsDetails = new DataSet();

adapter.Fill(dsLoadAllTabsDetails);

adapter.Dispose();



// DTToExcel(dsLoadAllTabsDetails);

}

返回;

Please any one help me I want to export dataset to excel sheet using excel dll from nuget in c# i don't want to use Microsoft.Office.Interop.Excel; i want to use only
using Excel; please help.

What I have tried:

this is my dataset. this dataset i want to download in excel.

using Excel;
string SqlCommand;
DataSet dsLoadAllTabsDetails;
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["LocalConnectionString"].ToString();

List<viewdatamodelapplication> objAPPLI = new List<viewdatamodelapplication>();
using (var conn = new SqlConnection(connectionString))
{
SqlCommand = "EXEC USP_Get_AllTabsDetails '" + partId + "'";
SqlDataAdapter adapter = new SqlDataAdapter(SqlCommand, conn);
dsLoadAllTabsDetails = new DataSet();
adapter.Fill(dsLoadAllTabsDetails);
adapter.Dispose();

// DTToExcel(dsLoadAllTabsDetails);
}
return "";

推荐答案

您引用的ExcelDataReader类不是用于写...的用法该类在名称中...用于READING。



您需要查看打开的xml并使用C#中的内容。如果不知道你想做什么,这是最好的起点。有一点需要注意,这只适用于excel 2007及更高版本(或者可能是2010年......无论他们切换到xml标准的版本)。如果这仍然不是你想要的,那么我害怕你想要做的事情将无法奏效。除了打开xml之外,你唯一的另一个选择就是使用Microsoft.Office.Interop.Excel或为某人编写的图书馆支付一大笔钱。



解决这个问题时,你需要把你的最终结果分解成更小的部分。这意味着,如果您想将整个数据集/表格写入电子表格,因为这是新库。首先,弄清楚如何将字符串写入电子表格。然后从那里获取数据列表,循环并写入电子表格。然后获取复杂类型的列表,并将其写入多个单元格。



一旦你完成了这些练习,你就对图书馆更加熟悉,自己想出来了,并且可以完成你正在尝试使用的任何课程。 。



使用Open XML SDK 2.0生成Excel 2010工作簿 [ ^ ]



如何:将文本插入电子表格文档中的单元格(Open XML SDK) [ ^ ]



使用Open XML SDK读取和编写Microsoft Excel [< a href =http://www.codepr oject.com/Articles/670141/Read-and-Write-Microsoft-Excel-with-Open-XML-SDKtarget =_ blanktitle =New Window> ^ ]



ClosedXML - OpenXML的简便方法 - 主页 [ ^ ]



如何使用OpenXML在.NET中创建Excel文件 - 第1部分:基础知识&#8211; Threading.DispatcherTimer [ ^ ]
The ExcelDataReader class you are referencing is not for writing...the usage of that class is in the name...its for READING.

You need to look into open xml and using that from C#. Without knowing exaclty what you want to do the, this is the best place to start. One thing to note, this only works with excel 2007 and later (or maybe its 2010...whatever version they switched to the xml standard). If this still isn't what you want then im afraid what you are trying to do won't work. Your only other option, other than open xml, is to use Microsoft.Office.Interop.Excel or pay a ton of money for some library that someone has written.

When tackling this problem you need to take your end result and break it into smaller pieces. Meaning, if you want to write a whole dataset/table whatever to a spreadsheet, since this is new library. Start by just figuring out how to write a string to a spreadsheet. Then from there, take a list of data, loop over it and write to a spreadsheet. Then take a list of a complex type, and write it to multiple cells.

Once you get through those exercises you are more familiar with the library, have figured it out yourself, and can probably accomplish whatever class it is you are trying to work with.

Generating Excel 2010 Workbooks by using the Open XML SDK 2.0[^]

How to: Insert text into a cell in a spreadsheet document (Open XML SDK)[^]

Read and Write Microsoft Excel with Open XML SDK[^]

ClosedXML - The easy way to OpenXML - Home[^]

How to create an Excel file in .NET using OpenXML – Part 1: Basics &#8211; Threading.DispatcherTimer[^]


这篇关于我想在C#中使用来自NuGet的excel DLL将数据集导出到excel表我不想使用microsoft.office.interop.excel;我想只使用excel;请帮忙..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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