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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:21:54+00:00 2026-05-14T02:21:54+00:00

Just posting the solution I worked out today. See my answer below. If you

  • 0

Just posting the solution I worked out today. See my answer below.

If you don’t have the very helpful OpenXML SDK v2.0 Tool, you can find it at http://www.microsoft.com/downloads/details.aspx?FamilyID=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en

If you know the purpose of the lines I commented with “I don’t know…”, please leave a comment explaining them.

  • 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-05-14T02:21:54+00:00Added an answer on May 14, 2026 at 2:21 am
    using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(spreadSheetFileName, true)) {
        WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
    
        // rId must be unique within the spreadsheet. 
        // You might be able to use the SpreadSheetDocument.Parts.Count() to do this.
        // i.e. string relationshipID = "rId" + (spreadsheetDocument.Parts.Count() + 1).ToString();
        string rId = "rId6";
    
        // Sheet.Name and Sheet.SheetId must be unique within the spreadsheet.
        Sheet sheet = new Sheet() { Name = "Sheet4", SheetId = 4U, Id = rId };
        workbookPart.Workbook.Sheets.Append(sheet);
    
        WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>(rId);
    
        Worksheet worksheet = new Worksheet();
        worksheet.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
    
        // I don't know what SheetDimension.Reference is used for, it doesn't seem to change the resulting xml.
        SheetDimension sheetDimension = new SheetDimension() { Reference = "A1:A3" };
        SheetViews sheetViews = new SheetViews();
        // If more than one SheetView.TabSelected is set to true, it looks like Excel just picks the first one.
        SheetView sheetView = new SheetView() { TabSelected = false, WorkbookViewId = 0U };
    
        // I don't know what Selection.ActiveCell is used for, it doesn't seem to change the resulting xml.
        Selection selection = new Selection() { ActiveCell = "A1", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A1" } };
        sheetView.Append(selection);
        sheetViews.Append(sheetView);
        SheetFormatProperties sheetFormatProperties = new SheetFormatProperties() { DefaultRowHeight = 15D };
    
        SheetData sheetData = new SheetData();
    
        // I don't know what the InnerText of Row.Spans is used for. It doesn't seem to change the resulting xml.
        Row row = new Row() { RowIndex = 1U, Spans = new ListValue<StringValue>() { InnerText = "1:3" } };
    
        Cell cell1 = new Cell() { CellReference = "A1", DataType = CellValues.Number, CellValue = new CellValue("99") };
        Cell cell2 = new Cell() { CellReference = "B1", DataType = CellValues.Number, CellValue = new CellValue("55") };
        Cell cell3 = new Cell() { CellReference = "C1", DataType = CellValues.Number, CellValue = new CellValue("33") };
    
        row.Append(cell1);
        row.Append(cell2);
        row.Append(cell3);
    
        sheetData.Append(row);
        PageMargins pageMargins = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.7D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
    
        worksheet.Append(sheetDimension);
        worksheet.Append(sheetViews);
        worksheet.Append(sheetFormatProperties);
        worksheet.Append(sheetData);
        worksheet.Append(pageMargins);
    
        worksheetPart.Worksheet = worksheet;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just looking for the first step basic solution here that keeps the honest people
just a quick question: I am a CS undergrad and have only had experience
Just how much slower are events? I have written a streaming XML parser (that
Just installed the latest SDK for iPhone 2.1. When I go to File ->
Just found this out, so i am answering my own question :) Use a
Just have a quick question about the GAC I created an assembly Awesome.DLL. Had
Just opening a WPF solution (not a winforms or any other solution) will cause
Just what the title says, I need to change the password for an existing
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.

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.