4

How can I programmatically take screenshot of an Excel cell range?

I'm currently using the Apache POI Java API to interact with excel documents, but I can't find any information on this use case. I'm open to other libraries and languages, as long as they can solve the problem and run in Linux.

SpeaksBinary
  • 185
  • 1
  • 17
  • An alternative api : https://docs.aspose.com/display/cellsjava/Named+Ranges. If this helps – Yohannes Gebremariam Mar 14 '17 at 19:45
  • Thanks @Yohannes. Hoping for a solution that doesn't cost several thousand dollars, but at least it's an option. – SpeaksBinary Mar 14 '17 at 20:01
  • I know that is a big chunk. in https://docs.aspose.com//display/cellsjava/Aspose.Cells+for+Java+Vs+Open+Source+Competitors. they actually compare it to its open source alternatives. You may take that opportunity to check those other api's other than Apache POI. May be you can try JExcelAPI – Yohannes Gebremariam Mar 14 '17 at 20:05
  • Silly question - can you use VBA in Linux? If so, I'm thinking you could navigate to the named range, and then just use `Application.SendKeys "(%{1068})"`? – BruceWayne Mar 14 '17 at 20:23
  • 1
    I guess you would have to render it yourself somehow. Apache POI allows you to read and modify the underlying data. How the data is presented, may differ. E.g. the same document opened in Excel and in LibreOffice might look slightly different. To my knowledge, Apache POI does not include any rendering functionality, it just holds the data. If you want a screenshot, you likely have to render it yourself somehow and store it as an image. – cello Mar 14 '17 at 20:37

1 Answers1

3

Using Java with the UNO API, open the document in LibreOffice and navigate to the specified cell range. Be sure to open the document as visible, not hidden.

Then use the code shown here to take a screenshot: https://stackoverflow.com/a/4490471/5100564.

Examples of Java with UNO are at http://api.libreoffice.org/examples/examples.html#Java_examples.

Community
  • 1
  • 1
Jim K
  • 12,824
  • 2
  • 22
  • 51