This is expression:

exp=Grid[{{Hyperlink@"http://www.wolfram.com", "this is first line"}, 
      {Hyperlink["http://mathematica.stackexchange.com"], "this is second line"}}, 
       Frame -> All]

I want to export it to HTML.

enter image description here

Export["test.html",exp] doesn't help and it throws error.

So I define a notebook, this is my first to to use Notebook programming, and I don't how to reproduce the same result as the above image.

notebook = Notebook[{
               BaseStyle -> "Hyperlink",
               ButtonData -> {"http://www.wolfram.com", None}], 
        "this is first line"}], 
               BaseStyle -> "Hyperlink",
               ButtonData -> {"http://mathematica.stackexchange.com", None}],
        "this is second line"}]

enter image description here

But when exporting, it changes.

Export["test", notebook, "HTML"]

enter image description here


This is what it looks like for me when I try to export the grid as HTML:


These are just the first couple of errors. It goes on like that. On the other hand, ExportString[exp, "HTMLFragment"] seems to work. A solution could then be to do something like this:

html = ExportString[exp, "HTMLFragment"]
  FileNameJoin[{$TemporaryDirectory, "grid.html"}],
  StringJoin["<html><body>", html, "</body></html>"],

This will export the table to an HTML file and open it in a browser, and the table looks the way you would expect it to look.

It would be good to report the problem to WRI. This looks like something that they would like to fix.

  • $\begingroup$ Thank you! But this is a little problem when using ExportString, ExportString["木", "HTMLFragment"] will throws error. If all character are English, it works fine. $\endgroup$ – partida Jun 2 '18 at 14:16
  • 2
    $\begingroup$ @partida Well, this is another problem. If you look at the stack trace then you will see that Export uses BinaryWrite to write the file. The documentation for BinaryWrite explicitly says that all characters must have a character code between 0 and 255. I think you should point this out to WRI, along with the original problem, so that they can both fix the recursion errors and make it possible to use international characters. (I so not rule out that there is a workaround, but I don't know any.) $\endgroup$ – C. E. Jun 2 '18 at 14:35
  • $\begingroup$ OK, I will send this to wolfram , and , i will add it to the question if have more information.Thanks anyway $\endgroup$ – partida Jun 2 '18 at 14:44

This works as expected in version 9 (Windows 10 64bit):

Export["test.html", Notebook[{Cell[BoxData[ToBoxes[exp]], "Output"]}], "HTML"]

How the exported file looks in Chrome:

enter image description here

  • 1
    $\begingroup$ it throws error again. Version: MMA 11.3.0 Linux $\endgroup$ – partida Jun 2 '18 at 14:01
  • $\begingroup$ Also bazillions of $RecursionLimit::reclim2 errors on MMA 11.3., macOS. $\endgroup$ – Henrik Schumacher Jun 2 '18 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.