2

I get an html file from the content of the HttpResponseMessage

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, myUrl);
var response = client.SendAsync(request);
var content = response.Content.ReadAsStringAsync().Result;

Then I'm trying to create an excel file

using(var Excel = Microsoft.Office.Interop.Excel)
{
   Excel.Application xlApp = new Excel.Application();
   Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(content);
}

And here I get an error message

Exception from HRESULT: 0x800A03EC

But if I manually copy all content from the response and create a file and then load it as

Excel.Workbook xlWorkbook = xlApp.Workbooks.Open("C:\test.html");

it works perfect. Can anyone explain please is it possible to create a Workbook from html string without saving a file?

1 Answers1

0

xlApp.Workbooks.Open needs to be passed a file path to work.

If you don't have a file path, you will want to use xlApp.Workbooks.Add instead (and not passing any parameters). See https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.add.aspx for more details.

mjwills
  • 23,389
  • 6
  • 40
  • 63
  • Thank you for your answer. Unfortunately xlApp.Workbooks.Add() doesn't work in my case (fails with the same exception). It looks like the best solution is to use something like HTML Agility Pack to parse HTML file (https://stackoverflow.com/questions/14968729/html-agility-pack-loop-through-table-rows-and-columns) – Egor Kovalev Aug 16 '17 at 14:51