【问题标题】:Setting Columns Width in Excel with C# VSTO使用 C# VSTO 在 Excel 中设置列​​宽
【发布时间】:2016-10-06 22:05:22
【问题描述】:

我将 C# 用于 VSTO Excel 插件。

目前我正在将列设置为自动安装:

newWorkSheet.Columns.AutoFit();

如何将列宽设置为有一些额外的填充?

在伪代码中是:

Column.Width = columnCurrentWidth + 10

对于某一列,使其比自动调整宽度稍宽

我已经弄清楚如何获取列的宽度但没有设置它

int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;

【问题讨论】:

    标签: c# excel vsto


    【解决方案1】:

    你必须设置ColumnWidthRowHeightRange

    这应该可行:

    int width = ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).Width;
    ((Excel.Range)newWorkSheet.Cells[rowCount, 2]).ColumnWidth = width + 10;
    

    【讨论】:

    • 我的问题有误; width 必须是 double 而不是 int,实际上它的 ColumnWidth 不是宽度。通过这两个更改,您的答案有效!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多