【问题标题】:Insert Excel row using format from row below, not above使用格式从下方插入 Excel 行,而不是上方
【发布时间】:2015-06-02 23:45:44
【问题描述】:

我需要使用 C# 在现有 Excel 工作表中插入一行,但保留现有格式。

Excel 中的默认行为是使用上面行的格式,在某些情况下这是我不想要的,因为这可能会有所不同。

我确信我已经看到有一种方法可以指定使用下面行的格式而不是上面的行,但我现在找不到它。

有人知道如何指定吗?

这是我正在使用的代码:

sheet.Range[string.Format("{0}:{0}", row)]
  .EntireRow
  .Insert(
  Excel.XlInsertShiftDirection.xlShiftDown);

【问题讨论】:

    标签: c# excel formatting add-on


    【解决方案1】:

    您还需要使用CopyOrigin 参数。

    sheet.Range[string.Format("{0}:{0}", row)]
      .EntireRow
      .Insert(
      Excel.XlInsertShiftDirection.xlShiftDown,
      Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow
    )
    

    有关Insertthat enum 的详细信息,请参阅此处。

    可以通过录制宏来获取这个参数。插入行时会弹出一个小框来选择格式的来源。

    【讨论】:

    • 太棒了,我会试一试的! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 2012-09-10
    相关资源
    最近更新 更多