使用excellibrary C#隐藏excel列 [英] hide excel column using excellibrary C#

查看:99
本文介绍了使用excellibrary C#隐藏excel列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已下载并在编码中使用了excellibrary。我需要帮助从数据库调用我的函数到excel。我无法隐藏某些列,例如id号。希望你能帮助我。我还需要帮助如何让多个数据库进入同一个excel。

以下是我的编码

  public   void  load_table_exec() //  这用于自动加载表//使用女性 
{
string constring = datasource = localhost; port = 3306; username = root; password =;
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand( select *来自database1.example;,conDataBase); //

try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();

bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);

DataSet ds = new DataSet( New_DataSet);
ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
sda.Fill(dbdataset);
ds.Tables.Add(dbdataset);

ExcelLibrary.DataSetHelper.CreateWorkbook( MyExcelFile.xls,ds) ;

}
catch (例外情况)
{
MessageBox.Show(ex.Message);
}

解决方案

更改SQL语句以仅返回要保存为excel的列

例如,如果你只想要column1,column2,column3那么

 MySqlCommand cmdDataBase =  new  MySqlCommand(  从database1.example中选择column1,column2,column3); 


I have download and used excellibrary in my coding. i need help in calling my function from database to excel. i cannot hide certain columns such as id number for example.. hope you can help me out. and i also need help how to make multiple database go to into same excel.
below is my coding

public void load_table_exec()// this is use to load table automatically //illi female
{
    string constring = "datasource=localhost; port=3306;username=root;password=";
    MySqlConnection conDataBase = new MySqlConnection(constring);
    MySqlCommand cmdDataBase = new MySqlCommand("select * from database1.example ; ", conDataBase); // 

    try
    {
        MySqlDataAdapter sda = new MySqlDataAdapter();
        sda.SelectCommand = cmdDataBase;
        DataTable dbdataset = new DataTable();
        sda.Fill(dbdataset);
        BindingSource bSource = new BindingSource();

        bSource.DataSource = dbdataset;
        dataGridView1.DataSource = bSource;
        sda.Update(dbdataset);

        DataSet ds = new DataSet("New_DataSet");
        ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
        sda.Fill(dbdataset);
        ds.Tables.Add(dbdataset);

        ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

解决方案

change the SQL statement to return only the columns you want to save as excel
example, if you want only column1, column2, column3 then

MySqlCommand cmdDataBase = new MySqlCommand("select column1, column2, column3 from database1.example");


这篇关于使用excellibrary C#隐藏excel列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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