0

Asp.Net を使用して一部のセルの色を設定したいと考えています。たとえば、私の給与額が 20000 より大きい場合、その特定のセルの色は赤になり、給与 > 20000 .other セルも同様です。私はデータベースから完全なデータを取得しており、最後にclosedXML dllを使用してデータをExcelファイルにエクスポートしています。私のすべてのデータはExcelファイルに保存されていますが、要件は完全に満たされています。

Excelを生成するための私のコード(Vb.Netで)

Public Sub GenerateExcel(ByVal DTExcel As DataTable, ByVal sFolder As String, ByVal email As String)
    Dim filepathemail As String = "", cntCol As Integer = 0, cntrow As Integer = 0, k As Integer = 0

    If DTExcel.Rows.Count > 0 Then
        ' string Sallary= ds.Tables[0].Rows[0]["Sallary"].ToString();

        Dim Excel As New XLWorkbook()

   If Sallary > 20000 Then
                //Here need to change the color of that cell (How to find cell)
  End if

        Dim worksheet = Excel.Worksheets.Add("Longcode SMS Log Report")
        worksheet.Cell(1, 1).InsertTable(DTExcel, True)

        worksheet.Tables.First().InsertRowsAbove(3)
        worksheet.Cell("A1").SetValue("Longcode SMS Log Report").Style.Font.FontName = "Calibri"
        worksheet.Cell("A1").Style.Font.Bold = True
        worksheet.Cell("A1").Style.Font.FontSize = 14
        worksheet.Range("A1:L1").Row(1).Merge()


        worksheet.Cell("A2").SetValue("Report Date : " & Format(ReportDate, "dd/MM/yyyy ")).Style.Font.FontName = "Calibri"
        worksheet.Cell("A2").Style.Font.Bold = True
        worksheet.Cell("A2").Style.Font.FontSize = 13
        worksheet.Range("A2:L2").Row(1).Merge()

        worksheet.Range("A3:L3").Row(1).Merge()

        Dim dttime As DateTime = DateTime.Now
        dttime = dttime.AddDays(-1)
        Dim hr As String = dttime.Hour
        Dim day As String = dttime.Day
        Dim mon As String = dttime.Month
        Dim yr As String = dttime.Year
        Dim dirPath As String = Application.StartupPath & "\Reports\" & sFolder
        If Not Directory.Exists(dirPath) Then
            Directory.CreateDirectory(dirPath)
        End If
        filepathemail = IO.Path.Combine(dirPath, "Longcode SMS Log Report_" & day & mon & yr & "_" + ".xlsx")
        Dim filepath As String = filepathemail
        Excel.SaveAs(filepath)
4

1 に答える 1