|
|
Home » Developing U++ » UppHub » Ole Automation [FEATURE REQUEST?]
Ole Automation [FEATURE REQUEST?] [message #17864] |
Sun, 31 August 2008 21:20 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
Do you have any program using Upp++ for Ole automation? (only windows). This serve to handle not only Office programs like Excel or Word but other like Catia 5.
If it does exist it could be prepared as a class that may be added to Bazaar.
Best regards
Koldo
Best regards
Iñaki
|
|
|
|
|
|
|
|
|
|
Re: Ole Automation [FEATURE REQUEST?] [message #19776 is a reply to message #17864] |
Sat, 17 January 2009 00:22 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
I am very happy to include in Bazaar the Automation library and a console demo.
It handles OpenOffice Calc and Writer and Microsoft Excel and Word.
I have prepared it thinking in simplicity. For example:
OfficeDoc doc;
if (OfficeDoc::IsAvailable("Open"))
doc.Init("Open")
else if (OfficeDoc::IsAvailable("Microsoft"))
doc.Init("Microsoft")
else
return;
doc.SetFont("Arial", 14);
doc.SetBold(true);
doc.WriteText("Hello all!");
doc.SetFont("Arial", 12);
doc.SetBold(false);
doc.SetItalic(true);
doc.WriteText("\n\nNon me latet [To replace] nonnullos vestrum");
doc.Select();
doc.Replace("[To replace]", "replaced text");
doc.Print();
doc.SaveAs("FileDemo", "doc");
doc.Quit();
So with the same set of functions it manages OpenOffice and Microsoft Office transparently fo the programmer.
The main classes declaration is like this:
class OfficeSheet
{
public:
OfficeSheet();
~OfficeSheet();
static bool IsAvailable(String type);
bool Init(char *type);
bool AddSheet(bool visible);
bool OpenSheet(String fileName, bool visible);
bool SetValue(int col, int row, Value value);
bool SetValue(String cell, Value value);
Value GetValue(int col, int row);
Value GetValue(String cell);
bool Replace(Value search, Value replace);
bool SetBold(int col, int row, bool bold);
bool SetBold(String cell, bool bold);
bool SetBold(bool bold);
bool SetFont(int col, int row, String name, int size);
bool SetFont(String cell, String name, int size);
bool SetFont(String name, int size);
bool Select(String range);
bool Select(int fromX, int fromY, int toX, int toY);
bool Select();
bool Print();
bool SaveAs(String fileName, String type = "xls");
bool Quit();
};
class OfficeDoc
{
public:
OfficeDoc();
~OfficeDoc();
static bool IsAvailable(char *program);
bool Init(char *type);
bool AddDoc(bool visible);
bool OpenDoc(String fileName, bool visible);
bool SetFont(String font, int size);
bool SetBold(bool bold);
bool SetItalic(bool italic);
bool WriteText(String value);
bool Select();
bool Replace(String search, String replace);
bool Print();
bool SetSaved(bool);
bool SaveAs(String fileName, String type = "doc");
bool Quit();
};
Unfortunately it only works in Windows (MinGW and MSC) using Ole Automation. As I have explained before the OpenOffice official interface called UNO has been too much for me until now.
Best regards
Koldo
Best regards
Iñaki
|
|
|
Re: Ole Automation [FEATURE REQUEST?] [message #21147 is a reply to message #19776] |
Tue, 05 May 2009 13:06 |
|
Hello Koldo!
Thank you for interesting OleAutomation.
I tried to buid Automation demo console with MSC9 and have following errors:
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__DeleteDC@4 referenced in function "bool __cdecl Window_SaveCap
ture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__DeleteObject@4 referenced in function "bool __cdecl Window_Sav
eCapture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__GetDIBits@28 referenced in function "bool __cdecl Window_SaveC
apture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__BitBlt@36 referenced in function "bool __cdecl Window_SaveCapt
ure(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__SelectObject@8 referenced in function "bool __cdecl Window_Sav
eCapture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__CreateCompatibleBitmap@12 referenced in function "bool __cdecl
Window_SaveCapture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
SysInfo.lib(SysInfo.obj) : error LNK2019: unresolved external symbol __imp__CreateCompatibleDC@4 referenced in function "bool __cdecl Wind
ow_SaveCapture(long,class Upp::String)" (?Window_SaveCapture@@YA_NJVString@Upp@@@Z)
C:\upp\out\MSC9.Force_size.Mt\Automation demo console.exe : fatal error LNK1120: 7 unresolved externals
With GCC MINGW have not errors and works fine!
|
|
|
|
|
|
|
Re: Ole Automation [FEATURE REQUEST?] [message #21156 is a reply to message #21152] |
Tue, 05 May 2009 21:33 |
|
Hello Koldo,
I have the same situation with this difference:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"
instead
"C:\Program Files\Microsoft SDKs\Windows\v6.1\lib"
The gdi32.lib library is located in folder:
"C:\Program Files\Microsoft SDKs\Windows\v6.1\lib"
I want to notice that when i tried to build this demo under MSC8 with the latest source svn code I have following errors:
----- SysInfo ( MT MSC8 FORCE_SIZE WIN32 MSC ) (3 / 5)
SysInfo.cpp
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1179) : error C2065: 'PRODUCT_ULTIMATE' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1179) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1182) : error C2065: 'PRODUCT_HOME_PREMIUM' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1182) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1185) : error C2065: 'PRODUCT_HOME_BASIC' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1185) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1188) : error C2065: 'PRODUCT_ENTERPRISE' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1188) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1191) : error C2065: 'PRODUCT_BUSINESS' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1191) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1194) : error C2065: 'PRODUCT_STARTER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1194) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1197) : error C2065: 'PRODUCT_CLUSTER_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1197) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1200) : error C2065: 'PRODUCT_DATACENTER_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1200) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1203) : error C2065: 'PRODUCT_DATACENTER_SERVER_CORE' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1203) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1206) : error C2065: 'PRODUCT_ENTERPRISE_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1206) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1209) : error C2065: 'PRODUCT_ENTERPRISE_SERVER_CORE' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1209) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1212) : error C2065: 'PRODUCT_ENTERPRISE_SERVER_IA64' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1212) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1215) : error C2065: 'PRODUCT_SMALLBUSINESS_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1215) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1218) : error C2065: 'PRODUCT_SMALLBUSINESS_SERVER_PREMIUM' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1218) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1221) : error C2065: 'PRODUCT_STANDARD_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1221) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1224) : error C2065: 'PRODUCT_STANDARD_SERVER_CORE' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1224) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1227) : error C2065: 'PRODUCT_WEB_SERVER' : undeclared identifier
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1227) : error C2051: case expression not constant
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1230) : warning C4060: switch statement contains no 'case' or 'default' labels
D:\source_codes\upp\svn_google\bazaar\SysInfo\SysInfo.cpp(1233) : error C2065: 'SM_SERVERR2' : undeclared identifier
SysInfo: 1 file(s) built in (0:01.29), 1297 msecs / file, duration = 1312 msecs, parallelization 0%
There were errors. (0:01.39)
Thank you for you contribution!
After build this with MINGW I can propouse to divide OfficeSheet into OfficeBook and OfficeSheet. It can be add possibility to add more sheets under one book (file)!
-
Attachment: untitled.JPG
(Size: 66.08KB, Downloaded 1802 times)
|
|
|
|
Re: Ole Automation [FEATURE REQUEST?] [message #21158 is a reply to message #21157] |
Wed, 06 May 2009 06:05 |
|
Hello Koldo!
When I put gdi32 in "package organizer" for SysInfo with MSC9 was compile and run OK! Please change this in svn (bazaar) too!
With MSC8 I modified your code and works too:
i modified:
#if !defined(PRODUCT_ULTIMATE)
#define PRODUCT_ULTIMATE 0x00000001
#define PRODUCT_HOME_BASIC 0x00000002
#define PRODUCT_HOME_PREMIUM 0x00000003
#define PRODUCT_ENTERPRISE 0x00000004
#define PRODUCT_HOME_BASIC_N 0x00000005
#define PRODUCT_BUSINESS 0x00000006
#define PRODUCT_STANDARD_SERVER 0x00000007
#define PRODUCT_DATACENTER_SERVER 0x00000008
#define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
#define PRODUCT_ENTERPRISE_SERVER 0x0000000A
#define PRODUCT_STARTER 0x0000000B
#define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
#define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
#define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
#define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
#define PRODUCT_BUSINESS_N 0x00000010
#define PRODUCT_WEB_SERVER 0x00000011
#define PRODUCT_CLUSTER_SERVER 0x00000012
#define PRODUCT_HOME_SERVER 0x00000013
#define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
#define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
#define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
#define PRODUCT_UNLICENSED 0xABCDABCD
#define SM_SERVERR2 89
#endif
instead:
#if defined(__MINGW32__)
//#define PRODUCT_UNDEFINED 0x00000000
#define PRODUCT_ULTIMATE 0x00000001
#define PRODUCT_HOME_BASIC 0x00000002
#define PRODUCT_HOME_PREMIUM 0x00000003
#define PRODUCT_ENTERPRISE 0x00000004
#define PRODUCT_HOME_BASIC_N 0x00000005
#define PRODUCT_BUSINESS 0x00000006
#define PRODUCT_STANDARD_SERVER 0x00000007
#define PRODUCT_DATACENTER_SERVER 0x00000008
#define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
#define PRODUCT_ENTERPRISE_SERVER 0x0000000A
#define PRODUCT_STARTER 0x0000000B
#define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
#define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
#define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
#define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
#define PRODUCT_BUSINESS_N 0x00000010
#define PRODUCT_WEB_SERVER 0x00000011
#define PRODUCT_CLUSTER_SERVER 0x00000012
#define PRODUCT_HOME_SERVER 0x00000013
#define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
#define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
#define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
#define PRODUCT_UNLICENSED 0xABCDABCD
#endif
be care... I added new define:
Maybe i did something wrong, but it was compiled and runed ok with all 3 compilers: MSC8, MSC9 and MINGW.
|
|
|
|
Re: Ole Automation [FEATURE REQUEST?] [message #21163 is a reply to message #21159] |
Wed, 06 May 2009 09:52 |
|
Hello Koldo!
I added new methods
for classes OfficeSheet and MSSheet:
// >>>Ion Lupascu 06.05.2009 Add this methods
int GetSheetsCount();
bool SetActiveSheet(int index);
bool SetActiveSheet(String name);
bool SetSheetName(String new_name);
// <<<Ion Lupascu 06.05.2009
Details for MSSheet:
// >>> Ion Lupascu 06.05.2009 Add this methods
int MSSheet::GetSheetsCount(){
if (!Book)
return(-1);
return((int)Ole::GetValue(Ole::GetObject(Book, "Sheets"), "Count"));
}
// Set active sheet start with 0(zero)
bool MSSheet::SetActiveSheet(int index){
if(!Book)
return false;
VariantOle index_ole;
index_ole.Int4(index + 1);
if (!(Sheet = Ole::GetObject(Book, "Sheets", index_ole)))
return false;
return true;
}
// Set active sheet by name
bool MSSheet::SetActiveSheet(String name){
if(!Book)
return false;
VariantOle name_ole;
name_ole.BString(name);
if (!(Sheet = Ole::GetObject(Book, "Sheets", name_ole)))
return false;
return true;
}
bool MSSheet::SetSheetName(String new_name){
if(!Sheet)
return false;
VariantOle new_name_ole;
new_name_ole.BString(new_name);
return Ole::SetValue(Sheet, "Name", new_name_ole);
}
// <<< Ion Lupascu 06.05.2009
Details for OfficeSheet:
// >>> Ion Lupascu 06.05.2009 Add this methods
int OfficeSheet::GetSheetsCount(){
if (!data)
return -1;
if (type == SheetOPEN)
return -1; //... need to add ((OPENSheet*)data)->GetSheetsCount();
else if (type == SheetMS)
return ((MSSheet*)data)->GetSheetsCount();
else
return -1;
}
// Set active sheet start with 0(zero)
bool OfficeSheet::SetActiveSheet(int index){
if (!data)
return false;
if (type == SheetOPEN)
return false; //... need to add ((OPENSheet*)data)->SetActiveSheet(index);
else if (type == SheetMS)
return ((MSSheet*)data)->SetActiveSheet(index);
else
return false;
}
// Set active sheet by name
bool OfficeSheet::SetActiveSheet(String name){
if (!data)
return false;
if (type == SheetOPEN)
return false; //... need to add ((OPENSheet*)data)->SetActiveSheet(name);
else if (type == SheetMS)
return ((MSSheet*)data)->SetActiveSheet(name);
else
return false;
}
bool OfficeSheet::SetSheetName(String new_name){
if (!data)
return false;
if (type == SheetOPEN)
return false; //... need to add ((OPENSheet*)data)->SetActiveSheet(name);
else if (type == SheetMS)
return ((MSSheet*)data)->SetSheetName(new_name);
else
return false;
}
// <<< Ion Lupascu 06.05.2009
I do not added this method for Open office. Please check this and add methods for Open calc too. Maybe exists memory leak in method:
// Set active sheet by name
bool MSSheet::SetActiveSheet(String name){
if(!Book)
return false;
VariantOle name_ole;
name_ole.BString(name);
>>HERE if (!(Sheet = Ole::GetObject(Book, "Sheets", name_ole)))
return false;
return true;
}
I tested this new methods and works fine!
Thank you for changes with MSC8 and gdi32.lib
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 10:33:05 CEST 2024
Total time taken to generate the page: 0.03907 seconds
|
|
|