Hang的笔记簿

  • 关于
杂记
记录我在传音的日子
  1. 首页
  2. AARDIO
  3. 正文

aardio-Excel使用技巧汇总

2020年12月05日 40点热度 0人点赞 0条评论

参考自bbs.aardio.com论坛

调用Excel简单示例

com.excel

import com.excel;
import console;

console.log("请稍候......")
var excel = com.excel()
//excel.Visible = true; //使Excel窗口可见
excel.alerts = false; //关闭所有操作提示

var book = excel.WorkBooks.Add() //创建工作簿
//book = excel.Open("/my.xls") //打开xls文件

var sheet = excel.ActiveWorkbook.Sheets(1);
var cell = sheet.Cells(1,1);
cell.Value2 = "haha"   

console.log( cell.Text )
excel.Quit(); //退出

wps.et

新版本wps的类名改为了 Ket.Application,原来是ET.Application

import wps.et;
import console;

console.log("请稍候......")
var et = wps.et()
//excel.Visible = true; //使Excel窗口可见
et.alerts = false; //关闭所有操作提示

var book = et.WorkBooks.Add() //创建工作簿 
//book = et.Open("/my.xls") //打开xls文件

var sheet = et.ActiveWorkbook.Sheets(1);
var cell = sheet.Cells(1,1);
cell.Value2 = "haha"   

console.log( cell.Text )
et.Quit(); //退出 

aardio操作Excel的一些技巧

1、边框的种类

xlContinuous 细实线
xlDash 虚线
xlDashDot 虚点线
xlDashDotDot 二点点线
xlDot 点线
xlDouble 二线
xlSlantDashDot 斜线
xlLineStyleNone 没有

 

这些常量值在aardio中com--excel库中有声明。
xlDialogFormatCharttype=423;
xlDivide=5;
xlDoubleOpen=4;
xlDoubleQuote=1;
xlVerbOpen=2;
xlDialogMacroOptions=382;
xlDialogTextToColumns=422;
xlExcelMenus=1;
xlExtended=3;
xlDialogGalleryColumn=69;
xlFill=5;
xlPartialScript=2;
xlDialogFillGroup=200;
xlDot=-4118;

excel.Range("a1:e20").borders(xlInsideHorizontal).LineStyle=xlDot 直接这样写是不可以的。要写成excel.Range("a1:e20").borders(12).LineStyle=-4118

 

边框的宽度(Weight) 边框的种类(LineStyle) 边框的位置
xlHairline 极细线 xlContinuous 实线 xlEdgeTop 单元格上端线
xlThin 细线 xlDash 波浪线 xlEdgeBottom 单元格下端线
xlMedium 中粗线 xlDashDot 虚点线 xlEdgeLeft 单元格左端线
xlThick 粗线 xlDashDotDot 二点线 xlEdgeRight 单元格右端线
xlDot 点线 xlInsideHorizontal 单元格内側的水平线
xlDouble 二重线 xlInsideVertical 单元格内側的垂直线
xlSlantDashDot 斜点线 xlDiagonalDown 左上到右下的斜线
xlLineStyleNone 没有线 xlDiagonalUp 左下到右上斜线

2、设置边框颜色、样式

import wps.et;

var excel = wps.et(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sheets = book.sheets(1)
import gdi
//实用哪个库中的对像就要先导入哪个库  
excel.Range("a1").Borders.color= gdi.RGB(255,0,0)
excel.Range("a3").Borders.color= gdi.RGB(0,0,0)
excel.Range("a5").Borders.color=0xFF0000
excel.Range("a7").Borders.LineStyle =-4119
excel.Range("a9").Borders(7).LineStyle =-4119
excel.Range("a11").Borders(10).LineStyle =-4119

3、获取有效行、列

只要单元格不是默认样式,就会被计算再有效行、列中。


//先打开Excel再运行
import com.excel;
import win;
var excel = com.excel(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sh = book.sheets(1)
win.msgbox(sh.UsedRange.Rows.Count ,"aardio")
win.msgbox(sh.UsedRange.Columns.Count ,"aardio")

4、自动填充、分页符操作例子

import wps.et;

var excel = wps.et(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sheets = book.sheets(1)

sheets.Cells(1,1).Value2 = "aardio1";
sheets.Range("A1").AutoFill(sheets.Range("A1:A20")); //自动填充20个数据

sheets.HPageBreaks.Add(sheets.Cells(11,1)); //添加水平分页符
sheets.PrintPreview();

//删除分页符
sheets.HPageBreaks(1).Delete();  

5、设置字体样式

import wps.et;

var excel = wps.et(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sheets = book.sheets(1)
import gdi
//字体样式
excel.Range("A3").ColorIndex = xlAutomatic
excel.Range("A3").Font.Name = "宋体"
excel.Range("A3").Font.Size = 20
excel.Range("A3").Font.color = 7
excel.Range("A3").Font.Strikethrough = False
excel.Range("A3").Font.Superscript = False
excel.Range("A3").Font.Subscript = False
excel.Range("A3").Font.OutlineFont = False
excel.Range("A3").Font.Shadow = False
excel.Range("A3").Font.Underline =-4119 /*xlUnderlineStyleNone*/
excel.Range("A3").Font.ColorIndex = xlAutomatic
excel.Range("A3").Font.Color = gdi.RGB(128, 0, 0)

6、自适应列宽

import wps.et;

var excel = wps.et(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sheets = book.sheets(1)
//自适应列宽
sheets.Cells.EntireColumn.AutoFit()
sheets.Cells.EntireRow.AutoFit()

//自动适应列宽行宽 2。
sheets.Cells.Columns.AutoFit()
sheets.Cells.Rows.AutoFit()

sheets.Range( "A1").HorizontalAlignment =-4108;   //水平居中
sheets.Range( "A1").VerticalAlignment =-4108;  //垂直居中

7、选中单元格

import wps.et;

var excel = wps.et(false)
excel.Visible = true;
var book = excel.ActiveWorkbook;
var sheets = book.sheets(1)

//选中单元格
sheets.Range("A5").Select()

8、调用宏

excel = com.CreateObject("Excel.Application")
excel.Run(“宏名字")

9、单元格背景色填充

sheet1.Cells( 1, 2 ).Interior.Pattern = 1                //填充模式
sheet1.Cells( 1, 2 ).Interior.ColorIndex = 6        //单元格背景--黄色

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2020年12月05日

Hang

点赞
< 上一篇

文章评论

取消回复

COPYRIGHT © 2020 TRANSSION LIFE. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS