vbs设置Excel表格格式

Set ExcelApp = CreateObject( "Excel.Application" )   
Set ExcelBook = ExcelApp.Workbooks.Open (filepath)
'指定sheet
Set ExcelSheet = ExcelApp.Sheets.Item(1)   
With ExcelSheet                       
'设置列宽
.Columns( "A:A" ).ColumnWidth = 20
.Columns( "B:B" ).ColumnWidth = 15
.Columns( "C:C" ).ColumnWidth = 10
.Columns( "D:D" ).ColumnWidth = 25
.Columns( "E:E" ).ColumnWidth = 20
.Columns( "F:F" ).ColumnWidth = 10
'以下设置方式均合法
.Columns( "A:f" ).ColumnWidth = 20      '指定从A列至F列的列宽
.Columns( "b" ).ColumnWidth = 20        '指定b列列宽
.Columns( "F" ).ColumnWidth = 20        '指定F列列宽
.Columns( "A:A" ).ColumnWidth = 20      '指定A列列宽
'设置行高
.Rows(1).RowHeight = 15
.Rows(2).RowHeight = 20
.Rows(3).RowHeight = 25
'设置显示区域的字体类型和大小
'字体类型            
.Range( "A:A" ).Font.Name = "Arial"
.Range( "B:B" ).Font.Name = "宋体"
.Range( "C:C" ).Font.Name = "黑体"
.Range( "D:D" ).Font.Name = "新宋体"
.Range( "E:E" ).Font.Name = "Times New Roman"
.Range( "F:F" ).Font.Name = "Times New Roman"
'以下设置方式均合法
.Range( "A:D" ).Font.Name = "Arial"
.Range( "a:b" ).Font.Name = "Arial"
.Range( "A:f" ).Font.Name = "Arial"
'字体大小
.Range( "A:A" ).Font.Size = 12
.Range( "B:B" ).Font.Size = 16
.Range( "C:C" ).Font.Size = 20
'以下设置方式均合法
.Range( "A:F" ).Font.Size = 6 
.Range( "a:b" ).Font.Size = 8
.Range( "A:f" ).Font.Size = 10
'给指定区域赋值
.Range( "A1" ).Value = "用例名称"           
.Range( "B1" ).Value = "测试号码"
.Range( "C1" ).value = "号码类型"
.Range( "D1" ).value = "执行时间"
.Range( "E1" ).value = "检查点描述"  
.Range( "F1" ).value = "检查结果"
'以下设置方式均合法
.Range( "a1" ).Value = "for"            'A1单元格内容为 for
.Range( "b:b" ).Value = "test"          'B列内容都为 test
.Range( "c:A" ).Value = "test"          '从A列至C列的内容均为 test
.Range( "a3:F3" ).Value = "great"       '第三行,从A至F列均为 great
.Range( "b3:E6" ).Value = "day"         '从B3单元格至E6单元格矩形区间范围的值均为 day
'合并居中
.Range( "B1:C1" ).Merge                 'B1单元格与C1单元格合并居中
'以下设置方式均合法
.Range( "a:f" ).Merge                   'A列至F列合并居中
.Range( "B3:g7" ).Merge                 '从B3单元格至G7单元格矩形区间合并居中
.Range( "a2:f2" ).Merge                 'A2,B2,C2,D2,E2,F2单元格合并居中
'设置文字颜色
'颜色取值范围:0~56
'0为无颜色
.Range( "A1" ).Font.ColorIndex = 5
'以下设置方式均合法
.Range( "g:G" ).Font.ColorIndex = 48       'G列的字体颜色设为48
.Range( "A:c" ).Font.ColorIndex = 28       'A列至C列的字体颜色设为 28
.Range( "b2:c2" ).Font.ColorIndex = 3      'B2至C2单元格字体颜色设为 3
.Range( "A1:c4" ).Font.ColorIndex = 9      'A1至C4单元格矩形区间字体颜色设为 9
'加粗
.Range( "A1" ).Font.Bold = True          
'以下设置方式均合法
.Range( "g:G" ).Font.Bold = True           'G列的字体设为粗体
.Range( "A:C" ).Font.Bold = True           'A列至C列的字体设为粗体
.Range( "b3:g5" ).Font.Bold = True         'B3至G5单元格矩形区间的字体设为粗体
.Range( "c1:G1" ).Font.Bold = True         'C1至G1单元格的字体设为粗体
'对齐方式
.Range( "A:A" ).HorizontalAlignment = 4        '右边对齐   A列所有行
.Range( "B:B" ).HorizontalAlignment = 1        '常规方式
.Range( "C:C" ).HorizontalAlignment = 2        '左对齐
.Range( "D:D" ).HorizontalAlignment = 3        '居中
.Range( "E:E" ).HorizontalAlignment = 5        '填充方式
'以下设置方式均合法
'单元格背景
'取值范围0~56
'0为无颜色
.Range( "A1:F1" ).Interior.ColorIndex = 45
'以下设置方式均合法
'以下语句可以显示所有颜色对应的数值
For i=1 to 56
    A= "A" &i
    B= "c" &i
    .Range(A).Interior.ColorIndex = i
    .Range(B).Value = i 
NEXT
'单元格边框
'Borders参数
'1左边框
'2右边框
'3上边框   
'4下边框   
'5左斜线   
'6右斜线   
'不可为0        
'其余作用未知   
'Linestyle参数  
'设置边框线条格式
'0不显示
'1实线条显示
'其余参数未知 
'不常用         
.Range( "A:F" ).Borders(1).LineStyle = 1
.Range( "A:F" ).Borders(2).LineStyle = 1
.Range( "A:F" ).Borders(3).LineStyle = 1
.Range( "A:F" ).Borders(4).LineStyle = 1
End with
'保存退出
ExcelBook.Save                 
ExcelBook.Close                 
Set ExcelBook = nothing
ExcelApp.Quit 
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
II(c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ 以下是一个可以实现你所需功能的vbs脚本: ```vbscript ' 打开Excel文件 Set obj II(b, c, d, a, x[13], S44, 0x4e0811a1); /* Excel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\path\to\excel\file.xlsx") 60 */ II(a, b, c, d, x[ 4], S41, 0xf7537e82); /*' 选择要操作的工作表 Set objWorksheet = objWorkbook.Worksheets("Sheet1") ' 获取行数和列数 61 */ II(d, a, b, c, x[11], S42, 0xbd3af235); /* intRowCount = objWorksheet.UsedRange.Rows.Count intColumnCount = objWorksheet.UsedRange.Columns.Count ' 循环遍历62 */ II(c, d, a, b, x[ 2], S43, 0x2ad7d2bb每一行 For i = 1 To intRowCount ' 创建txt文件并写入内容 Set objFSO =); /* 63 */ II(b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ state[0] += a; state[1] += b; state[2] += c; CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("C:\path\to\output\folder\" & i & ".txt", True) For j = 1 To intColumnCount strCellValue = objWorksheet.Cells(i, state[3] += d; /* Zeroize sensitive information. */ memset(x, 0, sizeof x); } /* MD j).Value objFile.Write strCellValue & vbTab Next objFile.Close ' 创建文件夹并移5 initialization. Begins an MD5 operation, writing a new context. */ static void MD5Init(MD5_CTX *context) { 动txt文件 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.CreateFolder(" context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->stateC:\path\to\output\folder\" & i) objFSO.MoveFile "C:\path\to\output\folder[0] = 0x67452301; context->state[1] = 0xefcdab89; context->\" & i & ".txt", objFolder.Path & "\" & i & ".txt" Next ' 关闭Excel objExcel.Quit state[2] = 0x98badcfe; context->state[3] = 0x10325476; } ``` 你需要将脚本中的 `C:\path\to\excel\file.xlsx` 替换为你的Excel文件路径/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ static void MD5Update(MD5_CTX *context, const unsigned char *input, unsigned int inputLen) { unsigned int i,将 `C:\path\to\output\folder\` 替换为你想要存储输出文件的文件夹路径。, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int)((context->count[0]运行脚本后,会在输出文件夹中创建100个文件夹,每个文件夹中包含一个txt文件,每个txt文件对应Excel表格中的一行数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值