导出excel
static void Job662(Args _args)
{
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelStyles styles;
SysExcelStyle ExcelStyle;
SysExcelFont ExcelFont;
COMVariant variant ;
COM comShapes;
COM comWorksheet;
;
excel = SysExcelApplication::construct();
books = excel.workbooks();
book = books.add();
//定义字体样式
styles = book.styles();
ExcelStyle = styles.add("bold");
ExcelFont = ExcelStyle.font();
ExcelFont.bold(true); //字体加粗,除此之外,SysExcelFont类下面还有设置字体颜色, 斜体字,添加删除线的方法。你也可以在该类下面添加设置字体名称,字体大小的方法。
Sheets = book.worksheets();
sheet = sheets.itemFromNum(1);
sheet.name("Sheet1");
excel.visible(true);
sheet.cells().item(2,2).value('ItemID');
sheet.cells().range('B2:C4').comObject().MergeCells(true);//指定的单元格合并
sheet.cells().range('B2:C4').style('bold'); //对该区域应用前面定义的style.
sheet.cells().range('B2:C4').horizontalAlignment(3);//水平居中对齐,在AX5.0的SysExcelRange 类里有现成的方法。同理,你可以依样化葫芦添加verticalAlignment()的方法进行单元格的垂直对齐方式。
If (WinAPI::fileExists(@"C:\Users\peng.chen\Pictures\TIAN_小甜甜.png"))
{
variant = new COMVariant();
variant.bStr(@"C:\Users\peng.chen\Pictures\TIAN_小甜甜.png");
comWorkSheet=sheet.comObject();
comShapes = comWorkSheet.shapes();
comShapes.addPicture(variant,1,1,100,100,80,80);
}
}
导入excel
static void KTL_CPeng_ImportItemName(Args _args)
{
int i;
str file;
FileNameFilter filter = ["@SYS57521",'*.xlsx', "@SYS101541",'*.xls'];
COMVariant COMVariant1;
SysExcelApplication app;
SysExcelWorkbooks Workbooks;
SysExcelWorkbook Workbook;
SysExcelWorksheets Worksheets;
SysExcelWorksheet Worksheet;
SysExcelCells Cells;
SysExcelCell RCell1, RCell2, RCell3,RCell4,RCell5,RCell6,RCell7,RCell8,RCell9;
;
try
{
file = Winapi::getOpenFileName(0, filter, '', "Open Excel Files");
app = SysExcelApplication::construct();
Workbooks = app.Workbooks();
COMVariant1 = new COMVariant();
COMVariant1.bStr(file);
Workbook = Workbooks.Add(COMVariant1);
Worksheets = Workbook.worksheets();
Worksheet = worksheets.itemFromNum(1);
Cells = Worksheet.Cells();
i = 2; // first line is a title, start line 2
RCell1 = Cells.Item(i, 1);
RCell2 = Cells.Item(i, 2);
RCell3 = Cells.Item(i, 3);
RCell4 = Cells.Item(i, 4);
RCell5 = Cells.Item(i, 5);
RCell6 = Cells.Item(i, 6);
RCell7 = Cells.Item(i, 7);
RCell8 = Cells.Item(i, 8);
RCell9 = Cells.Item(i, 9);
ttsbegin;
while (RCell2.value().bStr() != "")
{
print cells.item(i, 2).value().bStr();
i++;
RCell1 = Cells.item(i, 1);
RCell2 = Cells.Item(i, 2);
RCell3 = Cells.Item(i, 3);
RCell4 = Cells.Item(i, 4);
RCell5 = Cells.Item(i, 5);
RCell6 = Cells.Item(i, 6);
RCell7 = Cells.Item(i, 7);
RCell8 = Cells.Item(i, 8);
RCell9 = Cells.Item(i, 9);
}
ttscommit;
app.quit();
info("Update Complete");
}
catch
{
info("Nothing Uploaded");
}
pause;
}