Worksheets.Add 方法 (Excel)Worksheets.Add method (Excel)
本文内容
创建新的工作表、图表或宏工作表。Creates a new worksheet, chart, or macro sheet. 新工作表成为活动工作表。The new worksheet becomes the active sheet.
语法Syntax
表达式。将(之前、之后、计数、类型)expression.Add (Before, After, Count, Type)
_表达式_一个代表**工作表** 对象的变量。expression A variable that represents a Worksheets object.
参数Parameters
名称Name | 必需/可选Required/Optional | 数据类型Data type | 说明Description |
---|---|---|---|
BeforeBefore | 可选Optional | VariantVariant | 指定工作表的对象,新建的工作表将置于此工作表之前。An object that specifies the sheet before which the new sheet is added. |
AfterAfter | 可选Optional | VariantVariant | 指定工作表的对象,新建的工作表将置于此工作表之后。An object that specifies the sheet after which the new sheet is added. |
CountCount | 可选Optional | VariantVariant | 要添加的工作表数。The number of sheets to be added. 默认值为 1。The default value is one. |
TypeType | 可选Optional | VariantVariant | 指定工作表类型。Specifies the sheet type. 可以是下列的**XlSheetType** 常量之一: xlWorksheet、 xlChart、 xlExcel4MacroSheet或xlExcel4IntlMacroSheet。Can be one of the following XlSheetType constants: xlWorksheet, xlChart, xlExcel4MacroSheet, or xlExcel4IntlMacroSheet. 如果要基于现有模板插入工作表,请指定模板的路径。If you are inserting a sheet based on an existing template, specify the path to the template. 默认值为 xlWorksheet。 |
按照上面的理论,Excel Add Worksheet 第一个参数为Before,第二个为After
在POWERHSELL中,Before的值也不能忽略,也不能为$Null,只可以为[System.Reflection.Missing]::Value
For Example:
$xl.Worksheets.add([System.Reflection.Missing]::Value,$xl.Worksheets.Item($xl.Worksheets.count))