Excel Interop - Add a new worksheet after all of the others

前端 未结 4 427
天命终不由人
天命终不由人 2020-12-15 16:17

I am trying to add a new worksheet to an Excel workbook and make this the last worksheet in the book in C# Excel Interop.

It seems really simple, and I thought the b

相关标签:
4条回答
  • 2020-12-15 16:32

    Looking at the documentation here http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.move(v=vs.80).aspx, it indicates that the 'after' object isn't a numerical position; it's the object representing the sheet you want to position your sheet after. The code should probably be something like (untested):

    workbook.Sheets.Add(After: workbook.Sheets[workbook.Sheets.Count]); 
    
    0 讨论(0)
  • 2020-12-15 16:33

    This should do the job:

    wSheet.Move(Missing.Value, workbook.Sheets[workbook.Sheets.Count]);
    
    0 讨论(0)
  • 2020-12-15 16:33

    This is the only way that works for me:

    xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.Add
        (System.Reflection.Missing.Value,
         xlWorkBook.Worksheets[xlWorkBook.Worksheets.Count], 
         System.Reflection.Missing.Value, 
         System.Reflection.Missing.Value);
    
    0 讨论(0)
  • 2020-12-15 16:37

    it works for me

    WorkBook.Worksheets.Add(
        System.Reflection.Missing.Value,
        WorkBook.Worksheets[WorkBook.Worksheets.Count], 
        1, 
        System.Reflection.Missing.Value);
    
    0 讨论(0)
提交回复
热议问题