PDA

View Full Version : Open excel file on buttonclick



anh5kor
12th May 2016, 09:07
I am trying to open a pdf and a excel file on button click.


connect(ui->button1,SIGNAL(clicked()),this,SLOT(OpenPdfFile()) );
void MainWindow::OpenPdfFile()
{
QDesktopServices::openUrl(QUrl("GMHeaderCheckTool_UserManual.pdf", QUrl::TolerantMode));//working perfectly

}
connect(ui->button2,SIGNAL(clicked()),this,SLOT(OpenExcelFile( )));
void MainWindow::OpenExcelFile()
{
// where ExcelFileName conatin the Path of the excel location
QString ExcelFileName = "d:/Tools/HeadercheckTool/Requirment/To Anil/To Anil/Tool.xlsx"
QDesktopServices::openUrl(QUrl(ExcelFileName, QUrl::TolerantMode));//Not working
}


When I am trying to open the Excel file I am getting the below error


d:/Tools/HeadercheckTool/Requirment/To Anil/To Anil/Tool.xlsx' failed (error 2)

Please let me know how can i open excel file?

Ginsengelf
12th May 2016, 10:55
Hi, try to add file:/// in front of the path. Maybe you also need to add " to your string because of the spaces in the path.

Best regards,

Ginsengelf

yeye_olive
12th May 2016, 11:37
Use QUrl::fromLocalFile().