如何使使用c#制作的自定义Excel工作表的外观与从SharePoint下载的类似

如何使使用c#制作的自定义Excel工作表的外观与从SharePoint下载的类似,c#,excel,console-application,export-to-excel,sharepoint-2016,C#,Excel,Console Application,Export To Excel,Sharepoint 2016,我使用csom制作了一个excel下载控制台应用程序,用于从SharePoint下载列表数据。我希望此excel如下所示:SharePoint excel: 当前我的自定义excel如下所示: 有人能帮我设置自定义excel的格式代码吗?我需要为任何长度的备用行设置格式 注意:以上SharePoint Excel是列表中所有项目的SharePoint OOTB导出到Excel功能。我的答案基于 在Excel工作表中使用工作表时,以下内容应该有效: // define your colors

我使用csom制作了一个excel下载控制台应用程序,用于从SharePoint下载列表数据。我希望此excel如下所示:SharePoint excel:

当前我的自定义excel如下所示:


有人能帮我设置自定义excel的格式代码吗?我需要为任何长度的备用行设置格式

注意:以上SharePoint Excel是列表中所有项目的SharePoint OOTB导出到Excel功能。

我的答案基于

在Excel工作表中使用
工作表
时,以下内容应该有效:

// define your colors (header, odd rows, even rows)
var HeaderColor = XlRgbColor.rgbAliceBlue;
var EvenRowColor = XlRgbColor.rgbLightBlue;
var OddRowColor = XlRgbColor.rgbWhite;

// get the column/row count
int ColumnCount = _;
int RowCount = _;

// set the header color
var firstHeaderCell = workSheet.Cells[1, 1];
var lastHeaderCell = workSheet.Cells[1, ColumnCount];
workSheet.Range[firstHeaderCell, lastHeaderCell].Interior.Color = HeaderColor;

// loop through all the rows
for(int i=2; i<=RowCount; i++)
{
    var currentColor = i%2 == 1 ? OddRowColor : EvenRowColor;

    var firstRowCell = workSheet.Cells[i, 1];
    var lastRowCell = workSheet.Cells[i, ColumnCount];
    // set row color based on i being even or odd
    workSheet.Range[firstRowCell, lastRowCell].Interior.Color = currentColor;
}
//定义颜色(标题、奇数行、偶数行)
var HeaderColor=XlRgbColor.rgbAliceBlue;
var EvenRowColor=XlRgbColor.rgb蓝色;
var OddRowColor=XlRgbColor.rgbWhite;
//获取列/行计数
int ColumnCount=389;;
int RowCount=u3;;
//设置标题颜色
var firstHeaderCell=workSheet.Cells[1,1];
var lastHeaderCell=workSheet.Cells[1,ColumnCount];
工作表.Range[firstHeaderCell,lastHeaderCell].Interior.Color=HeaderColor;
//循环遍历所有行

对于(int i=2;i导出excel时使用的库是什么?另外,请输入导出excel时使用的代码我使用的是Microsoft.Office.Interop.excel库…为什么需要导出excel代码???我只需要进行格式化。可能需要对备用行进行格式化。只需对
循环使用
,然后检查呃,索引是奇数或偶数,并相应地更改颜色。我正在使用Microsoft.Office.Interop.Excel库。非常感谢!!!这很有帮助!!!