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

  • SEARCH
  • Home
  • 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 8339699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:57:07+00:00 2026-06-09T04:57:07+00:00

All of a sudden this code has stopped outputting an Excel File. It was

  • 0

All of a sudden this code has stopped outputting an Excel File. It was converting a DataTable, dtOutput, into an Excel file:

if (dtOutput.Rows.Count > 0)
{
    DataView dv = dtOutput.DefaultView;
    dv.Sort = "Outage Start Time";
    dtOutput = dv.ToTable();
    // Populates a column of the table
    dtOutput = addIncidentCounts(dtOutput);

    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
    Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
    Worksheet ws = (Worksheet)wb.Worksheets[1];
    ws.Name = "Retail Network Tracking Log";

    int col = 1;
    foreach (DataColumn column in dtOutput.Columns)
    {
        ws.Cells[1, col].Value2 = column.ColumnName;
        col++;
    }

    for (int i = 0; i < dtOutput.Rows.Count; i++)
    {
        for (int j = 0; j < dtOutput.Columns.Count; j++)
        {
            ws.Cells[i + 2, j + 1].Value2 = dtOutput.Rows[i][j];
        }
    }

    foreach (Range range in ws.UsedRange.Columns)
    {
        range.HorizontalAlignment = XlHAlign.xlHAlignLeft;
        range.Columns.AutoFit();
    }

    Range rangeE = ws.get_Range("E:E", Type.Missing);
    rangeE.NumberFormat = "d-mmm-yyyy hh:mm:ss";

    Range rangeF = ws.get_Range("F:F", Type.Missing);
    rangeF.NumberFormat = "d-mmm-yyyy hh:mm:ss";

    wb.Close(false, false, Type.Missing);
    xlApp.Quit();
    Marshal.ReleaseComObject(wb);
    Marshal.ReleaseComObject(xlApp);

    this.Close();
}

It has worked perfectly for weeks. I have made no changes to it. I have restarted VS, rebooted the computer, and finally reinstalled VS but I am still not getting any output. I have run it through the debugger as well and the code is definitely executing and attaining all of the proper values. I’m stumped.

  • 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-09T04:57:10+00:00Added an answer on June 9, 2026 at 4:57 am

    Hans Passant was right. The call to close needed to be:

    wb.Close(true, saveDirectory + "\\" + reportName, false);
    

    Now the real mystery is how this code was working in the first place!

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

Sidebar

Related Questions

This was all working before and all the sudden it stopped working and I
All of a sudden, Facebook sharing has stopped working on my site. It's been
I closed the main.xml Layout file in Eclipse, and all of the sudden, this
This is the code that I made that has worked but all of a
I periodically get this problem where all of a sudden mako is using old
I know this might sound really ridiculas but all of a sudden when I
All of a sudden my app is handing this out in the application event
I am extremely confused why I am getting this strange error all the sudden:
All of a sudden my form link looks like this: <form action=/r.ashx/Models.Module_ContactUs?action=Submit&amp;controller=Contact id=contactUsForm method=post>
I currently have this line of code which has been working for the past

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.