简体   繁体   English

如何在Spreadsheet Light中为已定义名称(范围)设置行高?

[英]How can I set the row height for a defined name (range) in Spreadsheet Light?

I am trying to convert Excel Interop code to Spreadsheet Light. 我正在尝试将Excel Interop代码转换为Spreadsheet Light。 The legacy Interop code I want to emulate is: 我要模拟的旧版Interop代码是:

var columnHeaderRowRange = _xlSheetFillRateByDistributorByCustomer.Range[
    _xlSheetFillRateByDistributorByCustomer.Cells[1, 1],
    _xlSheetFillRateByDistributorByCustomer.Cells[1, 16]];
columnHeaderRowRange.Interior.Color = Color.LightBlue;
columnHeaderRowRange.RowHeight = 12;
columnHeaderRowRange.Font.Bold = true;
columnHeaderRowRange.Font.Size = 11;

I'm creating a defined name (new designation, or Spreadsheet Light's description, of a range) like so, in Spreadsheet Light-ese: 我正在Spreadsheet Light-ese中创建定义的名称(新名称,或Spreadsheet Light的范围描述),如下所示:

SLDocument sl;
. . .
sl.SetDefinedName("columnHeaderRowRange", "Sheet1!$A$1:$P$4");

I would think I could set the row height for the range something like this: 我想我可以像这样设置范围的行高:

sl.SetRowHeight("columnHeaderRowRange", 12);

...but that doesn't work; ...但这是行不通的; the first arg must be an int (row index). 第一个arg必须是一个int(行索引)。

So I thought maybe I could add it to a style that I could then apply to the defined name: 所以我想也许可以将其添加到一种样式中,然后再应用于定义的名称:

SLStyle headerStyle = sl.CreateStyle();

..and then apply that style to the defined name like so: ..然后将该样式应用于定义的名称,如下所示:

sl.SetCellStyle("columnHeaderRowRange", headerStyle); // Remember Merle Haggard!    

...but I see no properties in SLStyle that will allow me to do that, either. ...但是我看不到SLStyle中的任何属性都可以使我做到这一点。

How can I control the height of all the rows within a defined name? 如何控制已定义名称中所有行的高度?

I think I have everything from the Excel Interop range converted over besides that in my style: 我认为除了样式之外,我还转换了Excel Interop范围中的所有内容:

headerStyle.Fill.SetPattern(DocumentFormat.OpenXml.
    Spreadsheet.PatternValues.Solid, Color.Black, Color.LightBlue);
headerStyle.Font.Bold = true;
headerStyle.Font.FontSize = 12;

The same thing could effectively be accomplished via: 可以通过以下方式有效地完成同一件事:

sl.SetRowHeight(1, 4, 12);

...or if you want the range to run through the last row added: ...或者如果您希望范围遍历添加的最后一行:

var stats = sl.GetWorksheetStatistics();
var rowcount = stats.NumberOfRows;
sl.SetRowHeight(1, rowcount, 12);

Although not being able to use a Range for some things with Spreadsheet Light, it seems pretty easy using values available via the GetWorksheetStatistics() method to accomplish handy tasks such as fit every row and column: 尽管无法在Spreadsheet Light中将Range用于某些用途,但是使用通过GetWorksheetStatistics()方法提供的值来完成诸如填充每一行和每一列之类的方便任务似乎很容易:

SLWorksheetStatistics wsstats = sl.GetWorksheetStatistics();
int rowCount = wsstats.NumberOfRows;
int colCount = wsstats.NumberOfColumns;

sl.AutoFitRow(1, rowCount);
sl.AutoFitColumn(1, colCount);

Of course, the values provided a defined name could be used, too, in suchlike instances: 当然,在类似的情况下,也可以使用提供的已定义名称的值:

sl.SetDefinedName("grandTotalRowRange",
        string.Format("Sheet1!${0}${1}:${2}${3}", 
            GetExcelTextColumnName(SHORTNAME_BYDCBYLOC_COL),
            rowToPopulate,
            GetExcelTextColumnName(QTYSHIPPED_BYDCBYLOC_COL),
            rowToPopulate)
        );

sl.AutoFitRow(rowToPopulate, rowToPopulate); // autofit the one row
sl.AutoFitColumn(SHORTNAME_BYDCBYLOC_COL, QTYSHIPPED_BYDCBYLOC_COL); // autofit the subset of columns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM