0

I'm working on a document printout from MS PowerApps. Best method I have found thus far is to write it in HTML and but save as a .doc file so that it opens in word online. From there, the user can save as PDF. So far, this works surprisingly well and allows for a great deal of control over the output, but one limitation I have found is that word does not seem to recognize multiple classes on a single element. This is kind of a pain as I am using a lot of tables, so I have to either create a new class for every single cell cell format I need or use inline CSS instead. Not huge issue, but it makes for messy code and time consuming updates. Is there any way to achieve this?

Edit: File here: https://wetransfer.com/downloads/29323f5c8060a374ed23e8ff2b6e9fd320210116015928/c991f4

It's designed to open in word online but it works in desktop as long as the view mode is set to print layout and not web layout.

Edit2: I should note that I did not figure out the headers all by myself, but worked off of some code provided by Georgi Nikolov found here

rb86
  • 33
  • 8
  • Seriously? I've googled extensively with no result. Have you? If you have the answer, please link me to it because it has eluded me so far. To be clear: Does NOT work. Only the first class is recognized by word. – rb86 Jan 16 '21 at 01:04
  • sorry about that. Why do you think css would work in a word doc. can you post or link the word.doc – DCR Jan 16 '21 at 01:11
  • If we want to apply an external CSS stylesheet to the current document in Microsoft Word. We may save your Word document as 'Web page (*.htm; *.html) first. We can't apply a css stylesheet to a .docx file directly as it's not html. – DCR Jan 16 '21 at 01:15
  • It's ok, I know people can be lazy sometimes, just not the case here. To answer the first question, I think CSS should work in a word doc, because well, for the most part, it does work. The file itself is an HTML format, but it's saved with a .doc extension so that when a user clicks the SharePoint link that I'm generating within my PowerApp, it automatically opens in word online. – rb86 Jan 16 '21 at 02:03
  • It's a hack for sure, but it's working very reliably so far. Also, it's specifically a .doc and not a .docx because it all has to be self contained rather than having external style sheets like a .docx would require. This is because the whole thing needs to be generated dynamically in PowerApps, then passed as text to Power Automate to generate the file in SharePoint. I know that all sounds crazy, but believe me it works quite well and is by far the best method I have found to print out of PowerApps. I have updated the post with a link to a generic version of the file. – rb86 Jan 16 '21 at 02:04
  • the problem may the quotes around the classes. check to make sure they are not rich text – DCR Jan 16 '21 at 02:23

1 Answers1

0

You can't write HTML or CSS Code into MS Word.

MS Word is Rich Text Editor Rich Text: Rich Text Format (RTF) is a file format that allows the exchange of text files between different editors and it has its formatting so we can't use it to write HTML.

HTML Must be written in Plain Text Editor because Plain text contains no formatting, only line breaks and spacing. Therefore no text formatting (such as font sizes and colors, bolding or italics) can be used.

some examples for Plain TextEditors that you can use to write HTML and CSS are Notepad and Notepad++

Omar M. Fathy
  • 121
  • 1
  • 1
  • 7
  • Indeed you can write HTML and CSS into a word file. I edited my post with a link to an example. It's actually just an HTML file saved with a .doc extension, but word reads it just fine. not sure how well it would hold up to editing, but that's not necessary in my case, as it's only intended to be open in word online and resaved as a pdf. – rb86 Jan 16 '21 at 02:09
  • Maybe I misunderstood your comment... I don't mean I am using word to WRITE the file. I'm writing it in VSCode. The file is being READ by word. The HTML/CSS works fine for the most part, it just doesn't recognize multiple CSS tags so I'm wondering if anyone has a workaround to get it to do so. – rb86 Jan 16 '21 at 02:19