Home » Developing U++ » UppHub » [SEMI-SOLVED] OfficeAutomation : How to Set Hyperlink to a Excel cell?
|
Re: OfficeAutomation : How to Set Hyperlink to a Excel cell? [message #33030 is a reply to message #33023] |
Sat, 02 July 2011 12:32 |
|
I try to add Method HyperLink to OfficeAutomation. But it not work
Where is my mistake?
bool MSSheet::Hyperlink(int col, int row, String hypertext, String hyperaddress) {
if (!App)
return false;
VariantOle x, y;
x.Int4(col);
y.Int4(row);
if (!(Sheet = Ole::GetObject(App, "ActiveSheet")))
return false;
ObjectOle Hyperlinks = Ole::GetObject(Sheet, "Hyperlinks");
ObjectOle Cell1 = Ole::GetObject(Sheet, "Cells", x, y);
VariantOle vCell;
vCell.ObjectOle(Cell1);
ObjectOle Link = Ole::GetObject(Hyperlinks, "Add", vCell);
String d;
if (Link != NULL) d= "Not Null"; else d="Null";
PromptOK("After assing & link is "+d);
VariantOle vAddr,vText;
vAddr.BString(hyperaddress);
vText.BString(hypertext);
Ole::SetValue(Link, "Address", vAddr) ;
Ole::SetValue(Link, "TextToDisplay", vText) ;
return true;
}
Please help!
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
[Updated on: Sat, 02 July 2011 12:38] Report message to a moderator
|
|
|
Re: OfficeAutomation : How to Set Hyperlink to a Excel cell? [message #33035 is a reply to message #33030] |
Sun, 03 July 2011 13:42 |
|
Semi-Solved!
Idea is to use Cell formula HYPERLINK.
I add function SetFormula(x,y,formula) to package OfficeAutomation.
Officeautomation.cpp:
bool MSSheet::SetFormula(int col, int row, String formula) {
if (!Sheet)
return false;
VariantOle x, y;
x.Int4(col);
y.Int4(row);
VariantOle val;
val.Value(formula);
//SetValue(col, row, (formula));
return Ole::SetValue(Ole::GetObject(Sheet, "Cells", x, y), "FormulaR1C1", val);
}
I'm not shure in this function for OOo(correct me please)
Officeautomation.cpp below:
bool OPENSheet::SetFormula(int col, int row, String formula) {
if (!SelCell(col, row))
return false;
VariantOle vText;
vText.BString(formula);
return Ole::Method(Cell, "setFormula", vText);
}
OfficeAutomationMethods.h after line 12:
Add line virtual bool SetFormula(int col, int row, String formula); \
OfficeSheet.cpp after line 107:
Add lines bool SheetPlugin::SetFormula(int col, int row, String formula) {return false;}
bool OfficeSheet::SetFormula(int col, int row, String formula) {return (static_cast<SheetPlugin *>(GetData()))->SetFormula(col, row, formula);}
This is my patch. Pls apply.
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
Re: OfficeAutomation : How to Set Hyperlink to a Excel cell? [message #33154 is a reply to message #33153] |
Mon, 11 July 2011 21:32 |
|
koldo wrote on Mon, 11 July 2011 19:25 | Hello Sergey
=HYPERLINK() is a very good idea.
Just try this with Automation demo:
sheet.SetValue("E23", "=hyperlink(\"http://www.ultimatepp.org\"; \"Ultimate link\")");
It will be included today in Bazaar.
|
This don't work. I already try it.
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
Re: OfficeAutomation : How to Set Hyperlink to a Excel cell? [message #33164 is a reply to message #33155] |
Tue, 12 July 2011 14:44 |
|
ratah
Messages: 107 Registered: July 2010
|
Experienced Member |
|
|
Hi,
I come here rarely, i'm busy with my job now.
I send you another library for OfficeAutomation and whatever you want : the "DispHelper"
It demonstrates using COM objects including ADO, CDO, Outlook, Eudora, Excel, Word, Internet Explorer, MSHTML, PocketSoap, Word Perfect, MS Agent, SAPI, MSXML, WIA, dexplorer and WMI
Here is the links
http://cvs.sourceforge.net/viewcvs.py/disphelper/disphelper/
sourceforge.net/projects/disphelper/
--------------
I use the plugin OfficeAutomation and have this little bug:
The EXCEL.EXE does not close correctly!
Here is a program test and bug report.
I do not know where is the problem.
|
|
|
|
|
|
Re: OfficeAutomation : How to Set Hyperlink to a Excel cell? [message #33181 is a reply to message #33180] |
Wed, 13 July 2011 14:05 |
|
My Code to work with OfficeAutomation:
void MainWindow::ExportExcel(){
SelectColumnsDlg dlg;
if(dlg.Execute() != IDOK)
return;
OfficeSheet sheet;
String fn = AppendFileName(GetDesktopFolder(), "Export.xls");
bool openAvailable = sheet.IsAvailable("Open");
bool microsoftAvailable = sheet.IsAvailable("Microsoft");
if (openAvailable) {
sheet.Init("Open");
}
if (microsoftAvailable) {
sheet.Init("Microsoft");
}
//if (!sheet.OpenSheet(fn, true)) {
sheet.AddSheet(true);
//}
int col=1;
#define eq(n,m,a) if (~dlg.n ==1) sheet.SetValue(col++, 1, m); a;
eq(opt_number,t_("Number"),)
eq(opt_address,t_("Address"),sheet.SetColWidth(col-1, 60))
eq(opt_time1,t_("Time from"),sheet.SetColWidth(col-1, 30))
eq(opt_time2,t_("Time to"),sheet.SetColWidth(col-1, 30))
eq(opt_price,t_("Price"),)
eq(opt_tax,t_("Tax"),)
eq(opt_makeprice,t_("Make price"),)
eq(opt_maketax,t_("Make tax"),)
eq(opt_size,t_("Size"),sheet.SetColWidth(col-1, 30))
eq(opt_link,t_("Link"),sheet.SetColWidth(col-1, 30))
eq(opt_status,t_("Status"),sheet.SetColWidth(col-1, 30))
sheet.Select(1, 1, col-1, 1);
sheet.SetBold(true);
int count=0;
LOG("Start Export--------------------------");
for(int i = 0; i < listobj.GetCount() ; i++) {
String link = LinkCalc(listobj(i,OBJ_ID));
if (listobj(i,Id("Select")) == 1) {
int col=1;
#undef eq
#define eq(n,m) if (~dlg.n ==1) sheet.SetValue(col++, i+2, m);
#define eq1(n,m) if (~dlg.n ==1) m;
eq(opt_number,AsString(count+1))
eq(opt_address,AsString(listobj(i,OBJ_ADDRESS)))
eq(opt_time1,DateConvert().Format(listobj(i,OBJ_TIME_FROM)))
eq(opt_time2,DateConvert().Format(listobj(i,OBJ_TIME_TO)))
eq(opt_price,FormatL(listobj(i,OBJ_PRICE)))
eq(opt_tax,AsString(listobj(i,OBJ_TAX)))
eq(opt_makeprice,FormatL(listobj(i,OBJ_MAKEPRICE)))
eq(opt_maketax,AsString(listobj(i,OBJ_MAKETAX)))
eq(opt_size,AsString(listobj(i,OBJ_SIZE)))
eq1(opt_link,sheet.SetValue(col++, i+2,"=HYPERLINK(\""+link+"\";\"Presentation\")"));
eq(opt_status,AsString(listobj(i,OBJ_STATUS)))
count++;
}
}
PromptOK("End Export&"+AsString(count)+" lines exported");
LOG("End Export----------------------------");
}
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 12:44:10 CEST 2024
Total time taken to generate the page: 0.03076 seconds
|