AX2012导入导出excel

本文详细介绍了如何使用VBScript与Excel进行数据导出与更新操作,包括创建工作簿、工作表、样式、字体、单元格等元素,并通过循环遍历数据进行数据填充与格式设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void export()
{
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelCells cells;

SysExcelStyles styles;
SysExcelStyle style;
SysExcelFont font;

COM comObject;

ARV_ParmBillingListLine_HZI m_billingLine;
ARV_TransportOrderTable_HZI m_ordertable;
PurchTable m_purchTable;
PurchLine m_purchLine;

int Excelrow = 1;
;

excel = SysExcelApplication::construct();
excel.visible(true);

books = excel.workbooks();
book = books.add();

styles = book.styles();
style = styles.add('bold');
font = style.font();
font.bold(true);

sheets= book.worksheets();
sheet = sheets.itemFromNum(1);
sheet.name('业务明细');
cells = sheet.cells();

this.createHead(sheet);

while select m_billingLine
where m_billingLine.BillingListId == g_billingList.BillingListId
{
m_purchTable = PurchTable::find(m_billingLine.SalesPurchOrderNum);

while select m_purchLine
where m_purchLine.PurchId == m_purchTable.PurchId
{
Excelrow++;
this.createBody(sheet, Excelrow, m_purchLine, m_billingLine);
}
}

Excelrow++;
this.createSum(sheet, Excelrow);

sheet.cells().range('A1:Y1').horizontalAlignment(3); //居中
sheet.cells().range('A1:Y1').style('bold');
sheet.cells().range('A1:Y1').comObject().AutoFormat();
sheet.cells().range('A1:Y1').formatConditions();
//sheet.cells().range('A1:Y1').comObject().AutoFilter();
sheet.columns().autoFit();
//comObject.AutoFormat();
//comObject.AutoFilter();
//book.saveAs(@'C:\Users\george\Desktop\XPO\Special Delivery Order.xlsx');
//excel.quit();
}

 

---------------------------------------------------------------------------------------------------

static void TPS_updateSDO_jay(Args _args)
{
str file;
FileNameFilter filter=["07-10",'*.xlsx',"97-02",'*.xls'];
COMVariant m_comvariant;

SysExcelApplication m_application;
SysExcelWorkbooks m_workbooks;
SysExcelWorkbook m_workbook;
SysExcelWorksheets m_worksheets;
SysExcelWorksheet m_worksheet;
SysExcelCells m_cells;
COMVariantType m_type; // Gets the COM object

int m_row;


Name m_instructionId;
ARV_TransportOrderTable_HZI m_order;
SalesLine m_salesLine;

;
try
{

file = Winapi::getOpenFileName(0, filter, '', "Open Excel Files");
m_comvariant = new COMVariant();
m_comvariant.bStr(file);


m_application = SysExcelApplication::construct();
m_workbooks = m_application.Workbooks();


m_workbook = m_workbooks.Add(m_comvariant);
m_worksheets = m_workbook.worksheets();
m_worksheet = m_worksheets.itemFromNum(1);
m_cells = m_worksheet.Cells();

m_type = m_cells.item(m_row+1, 1).value().variantType();
m_row = 1;


while (m_type != COMVariantType::VT_EMPTY)
{
m_row++;

m_type = m_cells.item(m_row+1, 1).value().variantType(); //when COMVariantType::VT_EMPTY ,this is the end

m_instructionId = m_cells.item(m_row, 1).value().bStr();

try
{

ttsBegin;
m_order = ARV_TransportOrderTable_HZI::find(m_instructionId, true);
m_order.TPS_IsSDO_JAY = NoYes::Yes;
m_order.doUpdate();

select firstOnly forUpdate m_salesLine
where m_salesLine.ARV_InstructionId_HZI == m_instructionId;
if(m_salesLine)
{
m_order.TPS_IsSDO_JAY = NoYes::Yes;
m_order.doUpdate();
}
ttsCommit;

}
catch
{}
}


}
catch
{
info("Nothing");
}

 

//m_application.quit();

info(int2str(m_row));
}

 

转载于:https://www.cnblogs.com/xiangliqi/p/4585049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值