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

江枫思渺然 提交于 2019-11-29 01:04:22
Dave

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]); 

This should do the job:

wSheet.Move(Missing.Value, workbook.Sheets[workbook.Sheets.Count]);
shiroxx

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!