Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed May 10, 2017 9:39 am

Hi,

I'm trying to use Spire.XLS in PowerShell v.5.0

What I need to do is load an .xlsx file and then save it as a .html

I have exported a powershell object into Excel via the ImportExcel module from Doug Finke which uses the EPPlus.dll library (Link: https://github.com/dfinke/ImportExcel).

Example command:
Code: Select all
$s = (Get-Content C:\temp\Servers.txt).toupper()
$list = Get-CimInstance -ComputerName $s -ClassName win32_logicaldisk -Filter "deviceid='d:'"
$list | Export-Excel -Path "c:\temp\Servers.xlsx" -Worksheetname "HDD Size"

Then I have manipulated the excel file to my liking (formatting in general like font and cell colors, borders, font sizes, merge cells, even added a chart, etc..).

So now I want to save/export this as a HTML file in order to upload it into an IIS server, so that anyone could see this report.

i have tried Add-Type -Path c:\...\spire.xls.dll or even [system.reflection.assembly]::LoadFrom("c:\...\spire.xls.dll") which both of them seem to work fine.

But after that, I can't fine any type that I can successfully load.
So for example when I'm doing: $obj = New-Object Spire.XLS
nothing happens. In fact I have tried with all of the type names in the dll, as I have run a foreach loop for all of the typenames starting with spire* but to no avail.

Could you please help me.

All I need is to use the spire.xls .NET component into PowerShell, has anyone done this before, and if so, can it even be done?
Or should I look for another solution in order to convert the excel files into HTML

Note: I need to do so without having excel of course, as this will be done on a Windows Server VM, where I don't have Office installed, so using a solution like "New-Object -ComObject" or something like "Microsoft.Office.Interop.Excel" is not suitable.

Thank you all,
Panos

panos.greg
 
Posts: 3
Joined: Sat May 06, 2017 10:27 am

Wed May 10, 2017 10:07 am

Dear Panos,

Thanks for your inquiry.
We will do an investigation and then update you ASAP.

Sincerely,
Betsy
E-iceblue support team
Last edited by Betsy.jiang on Thu May 11, 2017 1:56 am, edited 1 time in total.
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed May 10, 2017 10:26 am

Thank you Betsy for your quick reply.

I will patiently wait for any news from you.

PS If you need any other technical details regarding the PowerShell commands, please feel free to ask me.

Panos

panos.greg
 
Posts: 3
Joined: Sat May 06, 2017 10:27 am

Thu May 11, 2017 8:50 am

Dear Panos,

Thanks for your response.
I have tested the case you mentiond using the latest Spire.XLS Pack Hotfix Version:7.12.11 and PowerShell v5.0 on my win7 64bit machine. It worked fine on my side. Please try to use this version. And here is my testing script code for checking.
Code: Select all
Add-Type -Path F:\powershell\Spire.XLS.dll
Add-Type -Path F:\powershell\Spire.Pdf.dll
$workbook = New-Object Spire.Xls.Workbook
$workbook.LoadFromFile("F:\powershell\sample.xlsx");
$sheet = $workbook.Worksheets[0];
$sheet.SaveToHtml("F:\powershell\result.html");

If there is still issue, please provide the following information for investigation.
1)OS information, e.g. win7 64bit
2).NET Framework version

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 12, 2017 3:53 pm

Hi Betsy,

Apologies for the late reply, was a bit busy lately.

So I tried out what you've written and all went well, it worked!! :-)

I did had to get the latest hotfix for Spire.XLS (ver 7.12.11) as the one I had didn't export the excel file into HTML properly, meaning I was only getting gibberrish inside the .html file. But once I put the latest version DLLs in the folder, all worked as expected.

Thank you so much for this, it really helped me out.

Oh one more thing, if I wanted to use the spire.pdf.dll, to export the excel file into PDF, what would be the name of the object that I should use ?
(so for example in the case of spire.xls.dll library, we used the spire.xls.workbook object)

And is there a way to identify this on my own, if I don't know the name of the object. If for instance I try to use another .net component of yours, like spire.doc or spire.presentation.

Thanks again

Panos Greg
-- One Happy Camper --

panos.greg
 
Posts: 3
Joined: Sat May 06, 2017 10:27 am

Mon May 15, 2017 2:20 am

Dear Panos,

Sorry for late reply as weekend.
Please note that exporting the excel file into PDF is the function of Spire.XLS. And you only need to change the last script I provided in previous post to convert Excel to PDF, here is all code for your kind reference.
Code: Select all
Add-Type -Path F:\powershell\Spire.XLS.dll
Add-Type -Path F:\powershell\Spire.Pdf.dll
$workbook = New-Object Spire.Xls.Workbook
$workbook.LoadFromFile("F:\powershell\sample.xlsx");
$workbook.SaveToFile("F:\powershell\result1.pdf",[Spire.Xls.FileFormat]::PDF);

In addition, here is the API for our products, hope this can help.
https://www.e-iceblue.com/Tutorials/API.html
If you still have any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS