none
Append a new cell to an existing row, Spreadsheet, Open XML 2.0 RRS feed

  • Question

  • Hi all

    I need to output some data in a particular order from my database to a spreadsheet. 

    A1 - AC1 will contain employee names/ids.  A2-A255 will contain questions asked. 

    I want to add these rows and columns first and then go back and add the cell values. Is this possible without having to save the file (in memorystream)? 

    Please let me know if more information is needed.  Thanks in advance!

    Friday, February 22, 2013 8:20 PM

Answers

  • sorry i hit the submit button and then tried to mark as answered but all my reponse went away.  I think I have it now.  here is what worked for me:

    public void GenerateReport(WorksheetPart worksheetPart)
    {
                Worksheet workSheet = new Worksheet();
                SheetData sheetData = new SheetData();
    
             // Code to add columns
                workSheet.Append(columns);
    
               // Code to add employees; add to first row       
                sheetData.Append(row);
    
    
               // Code to add Questions
    	Foreach loop Questions
                 {	
    	 // Add questions to first column
                    sheetData.Append(row);
                 }
    
              
              // Need to do this ONLY if you want to add data to existing Rows
                workSheet.Append(sheetData);
                worksheetPart.Worksheet = workSheet;
    
    
               // Now the Answers            
                foreach Answer loop
                {
    	// Find if row exists 
    	// Add text to cell
    	workSheet.Save();
                }
                                    
            }
    
    Thank you for responding!
    • Marked as answer by ChileKitty Monday, March 4, 2013 9:58 PM
    Monday, March 4, 2013 9:57 PM

All replies

  • Hi ChileKitty,

     Is this possible without having to save the file (in memorystream)?

    Would you please clarify your goal more detailed. It's based on my experience that spreadsheet must be saved to keep the change.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 26, 2013 7:02 AM
    Moderator
  • Hello Tom...thank you for responding and sorry for my delay getting back to you.  What I meant is not saving to a physical file when adding a new cell.  So hopefully this makes more sense. 

    1) I first build column and append to worksheet

    2) I then add the employees as column headers

    3) Then for eaach question I add a row BUT only add the first cell

    4) Then for each row, I add a new cell for each employee's answers

    Daisy Jack Paul Betty
    Age
    Married?
    Children?
    Job Title
    • Marked as answer by ChileKitty Monday, March 4, 2013 9:54 PM
    • Unmarked as answer by ChileKitty Monday, March 4, 2013 9:54 PM
    Monday, March 4, 2013 9:26 PM
  • sorry i hit the submit button and then tried to mark as answered but all my reponse went away.  I think I have it now.  here is what worked for me:

    public void GenerateReport(WorksheetPart worksheetPart)
    {
                Worksheet workSheet = new Worksheet();
                SheetData sheetData = new SheetData();
    
             // Code to add columns
                workSheet.Append(columns);
    
               // Code to add employees; add to first row       
                sheetData.Append(row);
    
    
               // Code to add Questions
    	Foreach loop Questions
                 {	
    	 // Add questions to first column
                    sheetData.Append(row);
                 }
    
              
              // Need to do this ONLY if you want to add data to existing Rows
                workSheet.Append(sheetData);
                worksheetPart.Worksheet = workSheet;
    
    
               // Now the Answers            
                foreach Answer loop
                {
    	// Find if row exists 
    	// Add text to cell
    	workSheet.Save();
                }
                                    
            }
    
    Thank you for responding!
    • Marked as answer by ChileKitty Monday, March 4, 2013 9:58 PM
    Monday, March 4, 2013 9:57 PM