小编Cam*_*ase的帖子

如何使用Interop C#隐藏Excel列和行

我创建了一个简单的库存界面,它将从我的界面上的数据网格视图中访问和显示数据,然后通过按钮点击将信息发送到Excel.此部分根据需要工作,但我想在发送信息后删除未使用的列和行.我目前正在使用VS 2015.我无法弄清楚要添加什么来实现这一目标.

//send to excel
    private void btnExport_Click(object sender, EventArgs e)
    {
        ActiveControl = txtSerial;
        // creating Excel Application
        Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

        // creating new WorkBook within Excel application
        Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);

        // creating new Excelsheet in workbook
        Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

        // see the excel sheet behind the program
        app.Visible = true;

        // get the reference of first sheet. By default its name is Sheet1.
        // store its reference to worksheet
        worksheet = workbook.Sheets["Sheet1"];
        worksheet = …
Run Code Online (Sandbox Code Playgroud)

c# excel worksheet office-interop excel-interop

4
推荐指数
1
解决办法
5305
查看次数

标签 统计

c# ×1

excel ×1

excel-interop ×1

office-interop ×1

worksheet ×1