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 8877325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:26:30+00:00 2026-06-14T19:26:30+00:00

Here’s the situation: on a certain page within SharePoint, a user clicks a button

  • 0

Here’s the situation: on a certain page within SharePoint, a user clicks a button in a webpart to create a report based on data in SharePoint. This report is an Excel document that is created through C# code. When the report is created, it will be uploaded to SharePoint. When the upload is done, the file will be automatically opened for the user so the file can be saved locally or printed or some other action.

Here’s a simplified version of how my code works:

//Prepare the data in a table
//Normally there are multiple rows and columns here
var fileName = "Report.xlsx";
var table = new System.Web.UI.WebControls.Table();
table.Rows.Add(new TableRow());
table.Rows[0].Cells.Add(new TableCell());
table.Rows[0].Cells[0].Text = "Some cell value";
CreateWorkbook("My Report", fileName, table);

private void CreateWorkbook(string name, string fileName, Table table)
{
    using (var doc = SpreadsheetDocument.Create(_tempfolder + fileName, SpreadsheetDocumentType.Workbook))
    {
        var sheetData = new SheetData();
        var excelRow = new Row { RowIndex = 1 };

        sheetData .AppendChild(excelRow);

        //Normally there's a loop here going over all the rows and columns
        var tableCellValue = table.Rows[0].Cells[0].Text;
        var excelCell = CreateTextCell("A", 1, tableCellValue);
        excelRow.AppendChild(excelCell);

        doc.AddWorkbookPart().AddNewPart<WorksheetPart>().Worksheet = new Worksheet(sheetData);
        doc.WorkbookPart.Workbook = new Workbook(
            new Sheets(
                new Sheet
                {
                    Id = doc.WorkbookPart.GetIdOfPart(doc.WorkbookPart.WorksheetParts.First()),                    
                    SheetId = 1,
                    Name = name
                }));
        doc.WorkbookPart.Workbook.Save();
        doc.Close();

        //Upload the file to SharePoint
        //Omitted as this is not the issue here
    }
}

private static Cell CreateTextCell(string col, int row, string cellValue)
{
    var cell = new Cell { DataType = new EnumValue<CellValues>(CellValues.InlineString), CellReference = col + row };
    var inlineString = new InlineString();
    var text = new Text { Text = value };

    inlineString.Append(l_objText);
    cell.Append(inlineString);

    return cell;
}

Everything in the code works fine and the Excel-file is succesfully created and uploaded and after all this Excel opens up and then I get following message:

enter image description here

Excel found unreadable content in ‘…’. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.

When I click Yes, Excel magically repairs and opens the content and everything is shown as normal. But where does this error come from? I have looked on the internet for this problem and in almost all the cases the source of this problem are macros, formulas and other exotic Excel-stuff. But in this case, only one cell is added with just a string-value.

Does anyone know how to solve this issue?

Edit:

Opening the file in Notepad is not a solution as this gives output like this:

PK ©QiAÙ9
1A A xl/workbook.xml ¢ (  í½I–%&/mÊ{JõJ×àt¡€$Ø@ìÁˆÍæ’ìiG#)«ÊeVe]f@Ìí¼÷Þ{ï½÷Þ{ï½÷º;N’÷ßÿ?\fdlöÎJÚÉž!€ªÈ?~|?”þÇ¿÷|ü{¼[”ée^7Eµüì£ÝñÎGi¾œV³byñÙGëö|ûà£ßãèñ»GWUývRUoSj¿l½ûì£yۮݽÛLçù”kÆÕ_ÒwçU½ÈZú³¾¸Û¬ê<›5óš·íêÑÝ»Ítž/²f\­ò%}w^Õ‹¬

The error “sneaks” into the file upon creation. When I create the file I save it in a temporary folder and from there I upload the file to SharePoint. Both the temp-file and the SharePoint-file contain the error, so the error must occur upon creation of the file. How is it possible that even adding a single text value to one single cell creates a corrupted document?

  • 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-14T19:26:32+00:00Added an answer on June 14, 2026 at 7:26 pm

    Thanks to this article I found the problem. With the OpenXmlValidator class you can easily find errors in a created file. In my case the problem was that the title/name of one of my sheets was longer than 31 characters and 31 seems to be the limit. Problem solved, so for anyone with a similar issue, I strongly recommend the use of the validator! 😉

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

Sidebar

Related Questions

Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here's the problem....I have three components...A Page that contains a User Control and a
Here's the situation, i want to have a user that can enter time on
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Basically, what I'm trying to create is a page of div tags, each has
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is my problem. Our tech. writer or customer service will often create new
Here is my problem.. I have the option to create(add) two new input fields,

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.