AX2012导入导出excel

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));
}

 

posted on 2015-06-18 09:53  香里七  阅读(967)  评论(0编辑  收藏  举报