Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:41:49+00:00 2026-06-15T16:41:49+00:00

The following code snippet I have is a function that accepts a rectangular matrix

  • 0

The following code snippet I have is a function that accepts a rectangular matrix of strings and a path to write an xls file. It puts the contents of the matrix into the cells of the Excel sheet, and applies some formatting based on the contents:

public static void WriteXL(string[,] matrix, string path)
{
    XL.Application app = new XL.Application();
    XL.Workbook wbk    = app.Workbooks.Add();
    XL.Worksheet wsht  = wbk.Worksheets.Add();

    for (int i = 0; i < matrix.GetLength(0); i++)
    {
        for (int j = 0; j < matrix.GetLength(1); j++)
        {
            int _i = i + 1;
            int _j = j + 1;

            if (matrix[i, 0] == "Day" || matrix[i, 0] == "Date")
            {
                wsht.Cells[_i, _j].Font.Bold            = true;
                wsht.Cells[_i, _j].Font.Italic          = false;
                wsht.Cells[_i, _j].Style.Font.Name      = "Arial";
                wsht.Cells[_i, _j].Style.Font.Size      = 12;
                wsht.Cells[_i, _j].Style.Interior.Color = NumberFromColor(Color.Yellow);
            }
            else if (j == 0)
            {
                wsht.Cells[_i, _j].Font.Bold            = false;
                wsht.Cells[_i, _j].Font.Italic          = true;
                wsht.Cells[_i, _j].Style.Font.Name      = "Arial";
                wsht.Cells[_i, _j].Style.Font.Size      = 12;
                wsht.Cells[_i, _j].Style.Interior.Color = NumberFromColor(Color.Beige);
            }
            else
            {
                wsht.Cells[_i, _j].Font.Bold            = false;
                wsht.Cells[_i, _j].Font.Italic          = false;
                wsht.Cells[_i, _j].Style.Font.Name      = "Arial";
                wsht.Cells[_i, _j].Style.Font.Size      = 10;
                wsht.Cells[_i, _j].Style.Interior.Color = NumberFromColor(Color.White);
            }

            wsht.Cells[_i, _j].Value = matrix[i, j];
        }
    }

    wbk.SaveAs(path);
    wbk.Close();
    app.Quit();
    app = null;

    GC.Collect();
    GC.WaitForFullGCComplete();
    GC.WaitForPendingFinalizers();
}

So if you can imagine, there are rows that begin with “Day” and “Date” which are delimiting rows, like headings. These rows have bold font and yellow background. With the exception of cells that fall on these delimiting rows, the left-most column has beige background and italic text. The remaining cells are normal text with white background.

When I open the produced xls file, this is not at all what I see. First of all, the entire worksheet is white. Secondly, “Day” (which comes before “Date”) is bold but has the wrong size.

It looks like the most recent colour used is applied to the entire worksheet, and font size changes are only applied for the next cell, not the cell I’m currently in.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:41:50+00:00Added an answer on June 15, 2026 at 4:41 pm

    Try dropping the .Style eg

    wsht.Cells[_i, _j].Font.Name 
    

    instead of

    wsht.Cells[_i, _j].Style.Font.Name 
    

    You want to operate on the cell itself, not on its Style, since any other cells on the sheet which share that Style will also be affected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have user-extensions.js that contain the following code of snippet: Selenium.prototype.doTypeRepeated = function(locator, text)
i have the following code snippet in my ANT File which compiles my project
I have the following code snippet where some strings are initialized in the if
I have following code snippet that i use to compile class at the run
I have the following code snippet: $(document).ready(function () { // bind 'regFormBody' and provide
I have the following code snippet. $(#days).keypress(function(e){ if(e.keyCode == 13){ self.validateNightModalForm(); } }); basically,
I have a shell-script that looks like the following code snippet: ... export updates=0
I have the following snippet of code. abstract class MrParent { public function __construct()
I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
I have written the following code to write a file on my local file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.