Axapta : Sending data to OpenOffice Calc by X++ using COM

การส่งข้อมูลจาก Axapta ไปให้ OpenOffice อีกวิธีก็คือ ใช้ API ที่ OpenOffice เตรียมไว้ให้ บวกกับคุณสมบัติด้าน COM ของ Axapta

ลักษณะโดยทั่วไปของโปรแกรมประเภท Spread Sheet ก็คือ
- 1 Document มีได้หลาย Sheets
- 1 Sheet มีได้หลาย Ranges หลาย Cells
- 1 Ranges สามารถประกอบได้จาก หลาย Cells
- 1 Cell ใส่ข้อมูลได้ 1 ชุด
ตามคู่มือของ OpenOffice ก็นำมาเขียนโดยใช้ X++ ได้ดังนี้


static void ooTest(Args _args)
{
COM OpenOffice;
COM oDeskTop;
COM oDocument;
COM oSheets;
COM oSheet;
COM oRange;
COM BorderStruct;
COMVariant arg;
COMVariant byte;
Array arr = new Array(Types::String);
str url;
int i;
;
OpenOffice = new Com("com.sun.star.ServiceManager");
oDeskTop = OpenOffice.CreateInstance("com.sun.star.frame.Desktop");

// create and initialize a COMVariant object
arg = COMVariant::createFromArray(arr);

//Create new document
oDocument = oDeskTop.LoadComponentFromURL("private:factory/scalc", "_blank", 0, arg);
oSheets = oDocument.getSheets(); //object นี้รับ sheet ทั้งหมด
oSheet = oSheets.getByIndex(0); // object นี้รับ sheet แรกมาเพื่อใช้ทำงาน

BorderStruct = OpenOffice.Bridge_GetStruct('com.sun.star.table.BorderLine');
BorderStruct.Color(24567057);
BorderStruct.LineDistance(0);
BorderStruct.InnerLineWidth(0);
BorderStruct.OuterLineWidth(1);

oRange = oSheet.getCellRangeByName("H2:I2");
oRange.merge(true); //รวม Cells

oRange.setPropertyValue("CellBackColor", 16764057); // format cell
oRange.SetPropertyValue("LeftBorder",BorderStruct);
oRange.SetPropertyValue("RightBorder",BorderStruct);
oRange.SetPropertyValue("TopBorder",BorderStruct);
oRange.SetPropertyValue("BottomBorder",BorderStruct);
//*****************************
for(i=1; i<10;i++)
{
oRange = oSheet.getCellByPosition(0,i);
oRange.SetValue(i);
oRange.setPropertyValue("CellStyle", "Result");
oRange = oSheet.getCellByPosition(1,i);
oRange.Setstring('????????');
oRange.setPropertyValue('CharPosture',100);
oRange = oSheet.getCellByPosition(2,i);
oRange.SetValue(i*i);
oRange.setPropertyValue('CharWeight',200);
oRange.setPropertyValue('CharUnderline',124);
oRange = oSheet.getCellByPosition(3,i);
oRange.SetString(date2str(today(),123,2,2,2,2,4));
oRange.setPropertyValue("CharColor", 500);
oRange.setPropertyValue('CharShadowed', True);
oRange = oSheet.getCellByPosition(4,i);
oRange.SetString(today());
oRange.setPropertyValue("CellBackColor", 0x99CCFF);
oRange.setPropertyValue("CharHeight", 12);
oRange.setPropertyValue("IsTextWrapped", True);
oRange = oSheet.getCellByPosition(5,i);
oRange.SetString(today());
oRange.setPropertyValue("CellStyle", "Date");
}
}


ลองเล่นดูนะครับ ลองหลายแบบ ๆ ตามคู่มือได้เลย (ตัวอย่างผมได้มาจาก web เป็นภาษารัสเซียครับ http://axforum.info/forums/showthread.php?t=18722&highlight=openoffice)

Comments

Popular posts from this blog

Artillery Hornet + OctoPrint + Klipper

ย้ายบ้าน

ใต้ร่มกาสาวพัตร