This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

SQL syntax highlighting in .docx with POI

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
See where your hand is? Not there. It's next to this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!