Excel API Library for .NET - Sample Browser | Document Solutions | Set gridline and background color
[
フレーム]
Refer to the following example code to see how to set the gridline and background color of the exported image.
// Create a png file stream
FileStream outputStream = new FileStream("SetGridlineAndBackgroundColor.png", FileMode.Create);
//create a new workbook
var workbook = new GrapeCity.Documents.Excel.Workbook();
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Range["A1"].Value = "Sales Report";
worksheet.Range["A1"].Font.Color = Color.FromArgb(56, 93, 171);
worksheet.Range["A1"].Font.Size = 24;
worksheet.Range["A1"].Font.Bold = true;
worksheet.Range["A3:E13"].Value = new object[,]
{
{ "Date", "Product", "Customer", "Amount", "Show" },
{ new DateTime(2021, 1, 1), "Bose 785593-0050", "Fabrikam, Inc.", 1886.00, 1 },
{ new DateTime(2021, 1, 3), "Canon EOS 1500D", "Alpine Ski House", 4022.00, null },
{ new DateTime(2021, 1, 4), "Haier 394L 4Star", "Coho Winery", 8144.00, null},
{ new DateTime(2021, 1, 7), "IFB 6.5 Kg FullyAuto", "Southridge Video", 8002.00, 1 },
{ new DateTime(2021, 1, 11), "Mi LED 40inch", "Coho Winery", 6392.00, null},
{ new DateTime(2021, 1, 25), "Sennheiser HD 4.40-BT", "Contoso, Ltd", 6444.00, 1 },
{ new DateTime(2021, 1, 30), "Iphone XR", "Southridge Video", 2772.00, null },
{ new DateTime(2021, 2, 4), "OnePlus 7Pro", "City Power & Light", 8674.00, 1 },
{ new DateTime(2021, 2, 5), "Redmi 7", "A. Datum Corporation", 2332.00, null },
{ new DateTime(2021, 2, 8), "Samsung S9", "Alpine Ski House", 5370.00, 1 }
};
worksheet.Range["D4:D13"].NumberFormat = "0ドル.00";
worksheet.Range["A3:E13"].Font.Color = Color.FromArgb(56, 93, 171);
worksheet.Range["A3:E3"].Font.Bold = true;
worksheet.UsedRange.AutoFit();
Excel.ImageSaveOptions options = new Excel.ImageSaveOptions();
// Set the background color of the exported image
options.BackgroundColor = Color.FromArgb(226, 231, 243);
// Set the gridlines of the exported image
options.ShowGridlines = true;
options.GridlineColor = Color.FromArgb(145, 167, 214);
worksheet.ToImage(outputStream, Drawing.ImageType.PNG, options);
// Close the image stream
outputStream.Close();
' Create a png file stream
Dim outputStream = File.Create("SetGridlineAndBackgroundColor.png")
' Create a new Workbook
Dim workbook As New Workbook
Dim worksheet As IWorksheet = workbook.Worksheets(0)
worksheet.Range("A1").Value = "Sales Report"
worksheet.Range("A1").Font.Color = Color.FromArgb(56, 93, 171)
worksheet.Range("A1").Font.Size = 24
worksheet.Range("A1").Font.Bold = True
worksheet.Range("A3:E13").Value = New Object(,) {
{"Date", "Product", "Customer", "Amount", "Show"},
{#2021年01月01日#, "Bose 785593-0050", "Fabrikam, Inc.", 1886.0, 1},
{#2021年01月03日#, "Canon EOS 1500D", "Alpine Ski House", 4022.0, Nothing},
{#2021年01月04日#, "Haier 394L 4Star", "Coho Winery", 8144.0, Nothing},
{#2021年01月07日#, "IFB 6.5 Kg FullyAuto", "Southridge Video", 8002.0, 1},
{#2021年01月11日#, "Mi LED 40inch", "Coho Winery", 6392.0, Nothing},
{#2021年01月25日#, "Sennheiser HD 4.40-BT", "Contoso, Ltd", 6444.0, 1},
{#2021年01月30日#, "Iphone XR", "Southridge Video", 2772.0, Nothing},
{#2021年02月04日#, "OnePlus 7Pro", "City Power & Light", 8674.0, 1},
{#2021年02月05日#, "Redmi 7", "A. Datum Corporation", 2332.0, Nothing},
{#2021年02月08日#, "Samsung S9", "Alpine Ski House", 5370.0, 1}
}
worksheet.Range("D4:D13").NumberFormat = "0ドル.00"
worksheet.Range("A3:E13").Font.Color = Color.FromArgb(56, 93, 171)
worksheet.Range("A3:E3").Font.Bold = True
worksheet.UsedRange.AutoFit()
' Set the background color and gridlines of the exported image
Dim options As New Excel.ImageSaveOptions With {
.BackgroundColor = Color.FromArgb(226, 231, 243),
.ShowGridlines = True,
.GridlineColor = Color.FromArgb(145, 167, 214)
}
worksheet.ToImage(outputStream, Drawing.ImageType.JPG, options)
' close the image stream
outputStream.Close()