• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQL syntax highlighting in .docx with POI

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm generating a .docx file using Apache POI. This file contains a lot of SQL code and is quite unreadable so I was thinking about coloring that code. Any idea how to achieve that?

I understand that POI doesn't have some highlighter to complete this task. I'm just looking for some idea of how to highlight it during file generation with POI.

Thanks!
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which JAR are you using?
A quick search of Apache POI shows there is a method to set the text color.
 
P Remec
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tapas Chand wrote:Which JAR are you using?
A quick search of Apache POI shows there is a method to set the text color.



Maybe my question is not clear enough. There's no problem in using Apache POI, I'm familiar with setColor method. I'm looking for a way to highlight code automatically, for example to change SQL string into HTML with CSS styles and then embed HTML into .docx file. Like copying highlighted code from Notepad++ into Word document.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting question which unfortunately I don't know the answer to. However there are word macros that can do this such as https://paulstuartoracle.wordpress.com/2013/04/10/syntax-highlighting-sql-code-in-word-with-a-vba-macro/

 
P Remec
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:Interesting question which unfortunately I don't know the answer to. However there are word macros that can do this such as https://paulstuartoracle.wordpress.com/2013/04/10/syntax-highlighting-sql-code-in-word-with-a-vba-macro/



Thank you for a suggestion but I think that you can't run macro using Apache POI.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I'd be surprised if you can run the macro using POI. But you may be able to save a workbook containing this macro, use POI to add your content and then when you open the word document run the macro to to apply the highlighting. Not ideal I grant you.

Alternatively you look at the macro code and use that as a basis to write Java code to apply the changes to the content using calls to POI methods.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic