Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > Работа с Sheets для Excel


Автор: AntonSaburov 18.4.2005, 10:04
Как работать с Excel из .NET - в частности работать с листами

В MSDN'е откапал. Я не стал переводить, чтобы сохранить оригинальность. Также сохранил "выделения". Если что-то не понятно - спрашивай.  ;-) 
How to: Add New Worksheets to Workbooks
You can add a new worksheet to a Microsoft Office Excel 2003 workbook, or create a copy of an existing sheet.

The Add method allows you to add a new sheet to the collection of sheets in the workbook.

To add a new worksheet to a workbook 

Use the Add method of the Sheets collection: 
Код

Excel.Worksheet newWorkSheet;
newWorkSheet = 
    (Excel.Worksheet)ThisWorkbook.Worksheets.Add(
    Type.Missing, Type.Missing, Type.Missing, Type.Missing);

The Copy method creates a copy of a sheet, and inserts the sheet at the location you specify. You can specify to insert the new sheet either before or after an existing sheet, if you like. If you do not specify, Excel creates a new workbook to contain the new sheet. 

To add a copied worksheet to a workbook 

The following code copies the first sheet in the current workbook and places the copy after the third sheet. 
Код

((Excel.Worksheet)(ThisApplication.ActiveWorkbook.Sheets[1])).Copy(
    Type.Missing, ThisApplication.ActiveWorkbook.Sheets[3]);


И еще. Бонус smile  ;-) 

How to: Delete Worksheets from WorkbooksSee Also
Delete method deletes a specified worksheet.
To delete a worksheet from a workbook 
Use the Delete method of the Sheets collection: 
Код

((Excel.Worksheet)ThisApplication.ActiveWorkbook.Sheets[1]).Delete();


Вообще, если MADN есть - набирай в поиске Excel Workbook Object. Открой соответствующую страницу. Внизу и будут необходимые Common Tasks. Успехов. ;-)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)