小编use*_*008的帖子

使用Excel中的不同颜色突出显示数据在Windows应用程序中使用C#

我正在使用Windows应用程序.我需要弄清楚如何在Excel中突出显示不同颜色和样式的数据.我正在使用C#将数据导出到excel.

这是我用于将DataTable导出到Excel的代码,

private void btnExportexcel_Click(object sender, EventArgs e)
{
    oxl = new Excel.Application();
    oxl.Visible = true;
    oxl.DisplayAlerts = false;

    wbook = oxl.Workbooks.Add(Missing.Value);

    wsheet = (Excel.Worksheet)wbook.ActiveSheet;
    wsheet.Name = "Customers";

    DataTable dt = clsobj.convert_datagrid_orderlist_to_datatable(dvgorderlist);

    int rowCount = 1;
    foreach (DataRow dr in dt.Rows)
    {
        rowCount += 1;
        for (int i = 1; i < dt.Columns.Count + 1; i++)
        {
            // Add the header the first time through
            if (rowCount == 2)
            {
                wsheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
            }
                wsheet.Cells[rowCount, i] = …
Run Code Online (Sandbox Code Playgroud)

c# excel formatting colors

4
推荐指数
1
解决办法
6623
查看次数

标签 统计

c# ×1

colors ×1

excel ×1

formatting ×1