0

In a calculation provided by my Windows server, I have to make Microsoft Excel involve because of technology limitations: I need to systematically open Excel inside the server, read content of an Excel file to generate a txt file, and then close the Excel.

To this end, I have installed Microsoft Office 2016 in the virtual machine of Microsoft Server 2012 R2. I host a webpage http://test.addbba.com/batch.html in the server: clicking on the button leads to running batch.php:

(* batch.php: *)
<?php
  echo "Hello world!";
  system("cmd /c C:/inetpub/testaddbbacom/generateFile.bat");
  // system("cmd /c C:/inetpub/testaddbbacom/openExcel.bat");
  echo "Bye world!";
?>

(* generateFile.bat: *)
echo "abc" > haha.txt

(* openExcel.bat: *)
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE"

Double-clicking generateFile.bat and openExcel.bat in windows server in Microsoft Remote Desktop works well; openExcel.bat does open Excel which works like on-premise.

By batch.php, system("cmd /c C:/inetpub/testaddbbacom/generateFile.bat"); works too. However, the problem is about system("cmd /c C:/inetpub/testaddbbacom/openExcel.bat");: after uncommenting that line, and clicking on the button, I don't see Excel launching in Microsoft Remote Desktop, and I don't know if anything is happening behind the screen.

To conclude, I have to use (i.e., open, close) Excel itself as a step of my automatisation in Windows server. Automating this in a windows desktop is easy, whereas how could I make it work in a Windows server?

Could anyone help?

Tie
  • 223
  • 1
  • 2
  • 11
  • 1
    What exactly is the problem you are trying to solve? Are you just trying to export .xls to .txt? – user5870571 Sep 10 '16 at 15:52
  • Yes, I am trying to converting the content of an .xls to .txt. It is hard to retrieve some contents without opening the file. – Tie Sep 10 '16 at 15:54
  • Have you tried using powershell instead of batch? With PowerShell you have Export-Csv. – user5870571 Sep 10 '16 at 15:56
  • I have done lots of investigation, the conclusion is reading the content of excel file without opening the file is quite limited. I have to open the file with Excel, even thought I don't see it... – Tie Sep 10 '16 at 15:59
  • Keep in mind of a lot of this is going to depend on how the data in .xls is structured. If you just want columns and rows output to comma separated values, then you really just want to convert .xls to .csv (if you actually output to .txt have you confirmed it will be formatted in the way you need it for whatever reason you want to export .xls to .txt?). If you decide you want to convert to .csv then this may be much simpler. – user5870571 Sep 10 '16 at 16:02
  • I need to read lots of things from an Excel file besides the cell values... – Tie Sep 10 '16 at 16:03
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/45193/discussion-between-user5870571-and-thomas). – user5870571 Sep 10 '16 at 16:03

0 Answers0