c# - 用c#卡住excel列

标签 c# excel freeze

我用 c# 生成了一个 excel spread-cheat,我想卡住第一列。 这是我使用的代码:

    public static void SaveToExcel(object[,] data)
    {
        Excel = Microsoft.VisualBasic.Interaction.CreateObject("Excel.Application", String.Empty);
        Excel.ScreenUpdating = false;
        dynamic workbook = Excel.workbooks;
        workbook.Add();

        dynamic worksheet = Excel.ActiveSheet;

        const int left = 1;
        const int top = 1;
        int height = data.GetLength(0);
        int width = data.GetLength(1);
        int bottom = top + height - 1;
        int right = left + width - 1;

        if (height == 0 || width == 0)
            return;

        dynamic rg = worksheet.Range[worksheet.Cells[top, left], worksheet.Cells[bottom, right]];
        rg.Value = data;

        // Set borders
        for (var i = 1; i <= 4; i++)
            rg.Borders[i].LineStyle = 1;

        // Set header view
        dynamic rgHeader = worksheet.Range[worksheet.Cells[top, left], worksheet.Cells[top, right]];
        rgHeader.Font.Bold = true;
        rgHeader.Interior.Color = 189 * (int)Math.Pow(16, 4) + 129 * (int)Math.Pow(16, 2) + 78;
        rg.EntireColumn.AutoFit();

        // Show excel app
        Excel.ScreenUpdating = true;
        Excel.Visible = true;
    }

你能帮帮我吗???

最佳答案

正确的解决方案是添加以下代码:

        worksheet.Activate();
        worksheet.Application.ActiveWindow.SplitColumn = 1;
        worksheet.Application.ActiveWindow.FreezePanes = true;

关于c# - 用c#卡住excel列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4105210/

相关文章:

c# - 如何在给定自引用表中的以下路由别名的情况下获取最后一个类别

c# - 拆分字符串并仅获取第一个值

c# - 数学概率

three.js - 如何删除图像解码调用的卡住

java - TinySound 锁定应用程序

ubuntu - gedit 3.2.1 文件浏览器 Pane 插件缓慢且无响应

c# - DataGridView设置列背景色的方法

c# - OpenXML SDK - Excel 范围

excel - 删除重复项,保留最后一个条目——优化

c# - 通过验证可编辑的下拉列表