标签:size 概念 写代码 code 16px 实例 com off books
实例1:书本中的内容(第7页):
程序清单1.1. 在Excel中从Application对象到Worksheet
Dim myWorkbooks As Excel.Workbooks = app.Workbooks Dim myWorkbook As Excel.Workbook = myWorkbooks.Item(1) Dim myWorksheets As Excel.Sheets = myWorkbook.Worksheets Dim myWorksheet As Excel.Worksheet myWorksheet = CType(myWorksheets.Item(1), Excel.Worksheet)
Visual basic 2013 中的控制台应用程序:
实现目标:获取第一个工作表的名称。
实现步骤:项目——>添加引用——>程序集——>扩展——>Microsoft.Office.Interop.Excel——>确定
编辑代码:
Imports excel = Microsoft.Office.Interop.Excel Module Module1 Sub Main() Dim app As excel.Application = New excel.Application Dim myWorkbooks As excel.Workbooks = app.Workbooks Dim myWorkbook As excel.Workbook = myWorkbooks.Add() Dim myWorkbook1 As excel.Workbook = myWorkbooks.Item(1) Dim myWorksheets As excel.Sheets = myWorkbook1.Worksheets Dim myWorksheet As excel.Worksheet myWorksheet = CType(myWorksheets.Item(1), excel.Worksheet) MsgBox(myWorksheet.Name) End Sub End Module
实现效果:
简化程序清单1.1中的代码为:
书中的内容:
Dim myWorksheet As Excel.Worksheet myWorksheet = CType(app.Workbooks.Item(1).Worksheets.Item(1), Excel.Worksheet)
编写代码:
Imports excel = Microsoft.Office.Interop.Excel Module Module1 Sub Main() Dim app As excel.Application = New excel.Application Dim myWorksheet As excel.Worksheet myWorksheet = CType(app.Workbooks.Add().Worksheets.Add(), excel.Worksheet) MsgBox(myWorksheet.Name) End Sub End Module
运行效果:
注:区分程序、工作簿、工作表的概念,程序就是我们安装的Excel,程序可以创建多个工作簿,一个工作簿可以创建多个工作表。我们平时所说的Excel文件就是工作簿,而工作簿是要用程序来创建的。
标签:size 概念 写代码 code 16px 实例 com off books
原文地址:https://www.cnblogs.com/xiehaofeng/p/12241353.html