简体   繁体   English

如何使用C#中安装的Excel外接程序创建Excel电子表格?

[英]How to create an excel spreadsheet with an excel add-in installed in c#?

I have created an excel spreadsheet using epplus library. 我已经使用epplus库创建了一个Excel电子表格。

In this spreadsheet there are few columns with drop downs. 在此电子表格中,几乎没有带下拉列表的列。

I need to make these drop downs searchable. 我需要使这些下拉列表可搜索。 We can make a drop down applied on a single cell, searchable using excel functions. 我们可以将下拉列表应用于单个单元格,可使用excel函数进行搜索。

But it is not possible to apply the same on all the cells within a column. 但是不可能对列中的所有单元格都应用相同的内容。

But this is achievable using excel add-ins like 'excel campus-the-list-search-add-in' ( https://members.excelcampus.com/products/the-list-search-add-in/categories/142180/posts/422610 ). 但这可以通过使用诸如'excel campus-the-list-search-add-in'这样的excel插件来实现( https://members.excelcampus.com/products/the-list-search-add-in/categories/142180 / posts / 422610 )。

I don't want each and every user to install the excel add-in when they are using the spreadsheet created from my application. 我不希望每个用户都在使用从我的应用程序创建的电子表格时安装excel加载项。

I want the add-in to be automatically added, when creating the spreadsheet from my .NET application using epplus library. 当我使用epplus库从.NET应用程序创建电子表格时,我希望加载项自动添加。

Your question is a bit confusing! 您的问题有点令人困惑! maybe this can help you: 也许这可以帮助您:

//Create the data set and table
DataSet ds = new DataSet("New_DataSet");
DataTable dt = new DataTable("New_DataTable");

//Set the locale for each
ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
dt.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;

//Open a DB connection (in this example with OleDB)
OleDbConnection con = new OleDbConnection(dbConnectionString);
con.Open();

//Create a query and fill the data table with the data from the DB
string sql = "SELECT Whatever FROM MyDBTable;";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter adptr = new OleDbDataAdapter();

adptr.SelectCommand = cmd;
adptr.Fill(dt);
con.Close();

//Add the table to the data set
ds.Tables.Add(dt);

//Here's the easy part. Create the Excel worksheet from the data set
ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM