8

我正在将一个SQLiteExcelC#. 它工作正常。我正在使用该Excel.Range.set_Value()方法。

如何格式化Excel.Range类似Excel's的格式(如表格)?

4

3 回答 3

12

扩展我的评论并添加到 D Stanley。

Range range = ws.get_Range("A1:D5");
wrksheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, range, missing, Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, missing).Name = "MyTableStyle";
wrksheet.ListObjects.get_Item("MyTableStyle").TableStyle = "TableStyleMedium1";
于 2013-02-06T21:00:23.393 回答
2

此示例选择活动工作表中每个单元格的矩形范围。此外,它使用 Range 的索引参数来获取范围点。此外,AddEx()(以及 Interop.Excel 中的大多数方法)使用默认参数,因此您不必使用 System.Reflection.Missing。

// define points for selecting a range
// point 1 is the top, leftmost cell
Excel.Range oRng1 = oSheet.Range["A1"];
// point two is the bottom, rightmost cell
Excel.Range oRng2 = oSheet.Range["A1"].End[Excel.XlDirection.xlToRight]
    .End[Excel.XlDirection.xlDown];

// define the actual range we want to select
oRng = oSheet.Range[oRng1, oRng2];
oRng.Select(); // and select it

// add the range to a formatted table
oRng.Worksheet.ListObjects.AddEx(
    SourceType: Excel.XlListObjectSourceType.xlSrcRange,
    Source: oRng,
    XlListObjectHasHeaders: Excel.XlYesNoGuess.xlYes);
于 2014-04-03T23:09:49.400 回答
-1

Here's the VBA that does it:

ActiveSheet.ListObjects.Add xlSrcRange, Range("$J$10:$N$12"), , xlYes

Shouldn't be too hard to translate into an automation call. You can read the documentation as well.

于 2013-02-06T20:55:02.563 回答