August 13th, 2009

You are currently browsing the articles from KomKid.Net written on August 13th, 2009.

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++ ได้ดังนี้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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)

Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and OpenOffice and Programming.

Axapta : Sending data to Excel by X++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  SysExcelApplication       SysExcelApplication;
  SysExcelWorksheet         SysExcelWorksheet;
  SysExcelWorksheets        SysExcelWorksheets;
  SysExcelWorkbooks         SysExcelWorkbooks;
  SysExcelWorkbook          SysExcelWorkbook;
  SysExcelRange             SysExcelRange;
  SysExcelCell              SysExcelCell;
  SysExcelCells             SysExcelCells;
  COMVariant                COMVariant1;
  #excel
// ข้างบนนี้ คือการ กำหนดตัวแปรกับ macro
  ;

  sysExcelApplication = SysExcelApplication::construct();
  sysExcelApplication.visible(false); //set ไม่ให้มัน show ตั้งแต่แรก
  sysExcelWorkbooks = sysExcelApplication.workbooks();
  COMVariant1 = new COMVariant();

  COMVariant1.bStr('\\\\Axaptaserver\\AxaptaSP4\\Excel\\Losses.xls');
  sysExcelWorkbook = sysExcelWorkbooks.add(COMVariant1); // สั่งให้เปิดไฟล์ที่กำหนดตามบรรทัดข้างบน
  SysExcelWorksheets = sysExcelWorkbook.worksheets();
  SysExcelWorksheet = SysExcelWorksheets.itemFromNum(1); // เลือกทำงานกับ Sheet ที่ 1
//  SysExcelRange = SysExcelWorksheet.cells().range(#ExcelTotalRange);

  SysExcelCell = SysExcelWorksheet.cells().item(1,1); // กำหนด cell ที่จะอ่านหรือเขียน
  SysExcelCell.value(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); // เขียนข้อความลงไปใน cell ที่กำหนดเมื่อกี้

Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and Programming.

Axapta : Sending data to OpenOffice Calc by X++ using OOCALCVB.dll

วิธีการนี้ต้องใช้ตัวช่วยคือ OOCALCVB.dll
1.Download DLL OOCALCVB.dll ไปไว้ในเครื่อง ปกติก็คือที่ C:\Windows\System32\

2.ใน Axapta เลือกเมนู Tools > Development tools > Wizards > COM Class Wrapper Wizard
2009-08-13_141006

3.คลิก Next แล้วก็ Brows หาไฟล์ในข้อ 1 แล้วก็คลิก Next

4.ป้อน oo ตรงช่อง Element Mask เพื่อเอาไว้สังเกต Classes ที่จะได้ แล้วคลิก Next จะได้รายการของ Class ที่เกิดจาก OOCALCVB.dll
2009-08-13_141552

5.คลิก Next แล้วรอจนเสร็จ ก็คลิก Finish

6.เปิดดู AOT จะเห็นว่ามี Class ใหม่เกิดขึ้นมาดังรูป
2009-08-13_141822

ต่อไปก็ลองเขียน X++ ติดต่อดู ดังตัวอย่าง

1
2
3
4
5
6
7
8
9
10
    ooCalc              ooCalc;
    #ooCOMDEF
   ;

   ooCalc          = new ooCalc();
   ooCalc.Workbooks().OpenFile("\\\\Axaptaserver\\AxaptaSP4\\Excel\\Losses.xls",false,"",false);

    ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").Value(66);
//    ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").SetString(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); //SetString อันนี้ใช้ไม่ได้
    ooCalc.ActiveWorkbook().ActiveSheet().Cells().Item("A1").Formula(strfmt("Losses of %1 from %2 to %3",fromDate,toDate)); //SetString ไม่ได้ ใช้ Formula แทนไปก่อน

Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and OpenOffice and Programming.

ข้อคิดจากเพชรพระอุมา : 2

ข้อคิดที่ได้จากเพชรพระอุมา วันที่ 2
- กระสุนหัวแข็ง ใช้ยิงคน มีอำนาจทุลุทะลวงร่างกาย
- กระสุนหัวอ่อน ใช้ยิงสัตว์ มีอำนาจทำลายล้างกระดูกและกล้ามเนื้อ

- การรอคอยอย่างไร้จุดหมาย ผู้ที่รู้เวลา (มีนาฬิกา) จะอึดอัดกว่า เพราะคอยแต่จะเช็คว่า เมื่อใดจะถึงเวลา
- การรอคอยอย่างรู้จุดหมาย ผู้ที่ไม่มีนาฬิกา จะกระวนกระวายกว่า เพราะไม่รู้ว่าเวลาผ่านไปเท่าใดแล้ว ใกล้จะจึงเวลาแล้วหรือยัง

- ถ้าฝันเห็นงู อาจจะได้คู่ แต่ถ้าเข้าป่าถูกงูรัดอาจตายได้ ถ้าไปสองคน ไม่ต้องตกใจ มันรัดทีเดียวสองคนไม่ได้ ให้ใช้มีดฟัน

Written by Komkid on August 13th, 2009 with no comments.
Read more articles on KomKid.

Ubuntu : gconf-editor

เครื่องมือใน GNOME คล้าย ๆ registry ของ Windows

Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Ubuntu.

« Older articles

No newer articles