Hi Avinash,We would appreciate it if you would come over to the dev list and contribute some of your implementations. Josh, Yegor and Nick can help you find a proper way to extend POI directly.
We plan to make a push to support OOXML as completely as possible, the more hands and heads the better :-)
Regards, Dave On Mar 24, 2009, at 9:57 AM, Avinash Kewalramani wrote:
Hi MarkI sent you the file via Rapidshare. Actually I already have piece of code which does what you are proposing.This is how I have support for embedded objects which are not yet supported by POI.I hate to use this pecial piece of code to inject xml at the end into a POi created file.It just seems risky and might fail. Here is what I do1.Reverse engineer the xml to understand the minimalistic xml I need to inject into the POi file to support a feature not yet supported by POI(e.g embedded objects, Hyperlinks on images)2. write out the POI file I want. 3. Write out the minimal XML I need to support the new feature4. use DOM4J with XSLT rules to merge the two files and voila you have a new file with the feature required.Thanks Avinash -----Original Message----- From: MSB [mailto:[email protected]] Sent: Tuesday, March 24, 2009 1:24 AM To: [email protected] Subject: RE: Writing html code to xls cellSorry to say this but I cannot see the attachment - and it is purely my fault as I am not registered with the POI list but view it through nabble.com.If you have the time, could you pease upload the file to a file sharing site - personally, I like to use www.rapidshare.com - and then post the link for me? I am confident that it should be possible to do some post processing on the file to 'insert' the hyperlinks after we have identified exactly what changes need to be made. To my mind, the first two steps are to identify the differences between the two files, to manually edit the 'non hyperlinked'version of the file to add the hyperlink and then - there's that thirdstep!! - create a class that will make the changes for us. Depending on your requirement, I can see a class with a static method that takes a reference to the .xlsx file and lists of the images and the hyperlinks to attach. Itshould all be quite good fun IMO and the only stumbling block could betiming - we need to make sure POI has finished writing the file before we begin working with it but I do know a trick if the methods do not block.Oh, thanks for the compliement in another of your posts, but there is no way that I am a good enough programmer now to be one of the developers of POI.itextaccel wrote:Hi Yegor and Mark First up thanks for the constant support on this issue.I did a little bit of digging into the xlsx files myself as Mark pointedout it lookslike the hyperlink is stored as part of the drawing.xml file and a newrelationship is created in drawing1.xml.relsI created a file using POI with one image in it.Then added a link to theimage in it manually andsaved it as another file, unzipped both and compared the directories andfound two files which have this information xl/drawing/_rels/drawing1.xml.rels xl/drawing/drawing1.xmlI have attached a zip dir with both the above files for both scenarioswith hyperlinks and w/oI think Plain Java injection of xml after creation might be the way for mebut if it is easy to build in POI then I will hold off on that for now. Regards A -----Original Message----- From: Yegor Kozlov [mailto:[email protected]] Sent: Saturday, March 21, 2009 9:46 AM To: POI Users List Subject: Re: Writing html code to xls cellthere are several types of hyperlinks in Excel that can be grouped in twocategories:(1) BIFF8 hyperlinks. These are stored in the BIFF format and supported byHSSF. (2) Drawing hyperlinks. These are assigned to drawing objects such as pictures and shapes. As far as I know, they are a part of the Escher stuff and stored somewhere in the shape's Escher container.In theory, drawing hyperlinks should be stored similarly in PowerPoint andExcel as they share the same drawing layer.If it is so, then adding this support is quite a realistic task. I onlyneed to check if it is really so :) YegorI have had the opportunity to dig around a little now and I do not thinkthat it is possible to use HSSF/XSSF to add a hyperlinked image to a worksheet.To me, the critical point is that when you create a hyperlinked imageusing Excel, firstly the image is placed on the sheet, next the image is selected and then hyperlink button clicked to open a dialog and specify the attributes - i.e. what you are linking to. So, it seems that the hyperlinkbecomes a 'property' of or is associated with the image so to speak. Itis certainly the case that the hyperlink is not entered into a cell - I movedthe image to see - and POI told me that the sheet contained no cells, noformulae, just a single picture. As far as I am aware, there is noopportunity to set attributes of this type - hyperlinks - for any imagesthat can be added to a worksheet using POI and that is why I have concluded it is not - in all likelihood - possible using the API. Sadly, I was not able to find out how the hyperlinkinformation/specification was bound using the BiffViewer/ EFBiffViewerutilities. Both correctly reported that a picture existed on the worksheet but it was not obvious where the hyperlink information was. The only thingthat I did not try - as I assumed all I would get was a copy of the image-was to stream the HSSFPictureData object I would have recovered from the sheet out to a file. If I have the time this weekend - lots of rugby to watch as the Six Nations competition comes to an end and I am working onSunday as well - I will do this just to see what I get.As you are using the xlsx file format - well I assume you are from you original email - it may be worthwhile creating a worksheet that holdsjust asingle hyperlinked image and then looking at the file's contents directly- not using POI. That may give you a clue about where the hyperlinkinformation is stored and - if it is easy enough to accomplish - you maybeable to amend the xlsx file 'manually' using core java; by this, I mean using POI to create the file and insert the image then core Java to addthehyperlinking information if such is possible as all xlsx files are iszipped xml. Sorry to admit that I cannot check this myself - I only have an earlierversion of Office installed on my PC and we are Office free now at work.Ifyou are not comfortable digging around inside the xlsx file, just createoneand send it to me, I will try having a look myself but cannot promisethat this approach can be made to work. itextaccel wrote:Thanks a lot MSB for your answer and also for taking the time(if possible) to look into this.I will try to dig on my own and see if I find something too.I will postit here if I do. Regards A -----Original Message----- From: MSB [mailto:[email protected]] Sent: Friday, March 20, 2009 12:42 AM To: [email protected] Subject: RE: Writing html code to xls cellWhen Satish and I talked about using hyperlinks, I said that I knew itwaspossible to add a hyperlink to a cell but that I did not know if it was possible to use an image as the anchor for the hyperlink. So I am sorrytosay that I do not know the answer to your question at this time. I willtake a look over the weekend if I have the time however. itextaccel wrote:sorry forgot to add the code block Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); //Workbook wb = new HSSFWorkbook(); CreationHelper helper = wb.getCreationHelper(); //add a picture in this workbook. InputStream is = new FileInputStream(args[0]); byte[] bytes = IOUtils.toByteArray(is); is.close(); int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); //create sheet Sheet sheet = wb.createSheet(); CellStyle hlink_style = wb.createCellStyle(); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font); Cell cell; //URL cell = sheet.createRow(1).createCell((short)1);Hyperlink link = helper.createHyperlink(Hyperlink.LINK_URL);link.setAddress("http://poi.apache.org/"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); sheet.setColumnWidth(1, sheet.getColumnWidth(0) *6); //create drawing Drawing drawing = sheet.createDrawingPatriarch(); //Reset the image to the original size. //picture.resize(); //picture.setLineStyle( picture.LINESTYLE_DASHDOTGEL ); //add a picture shape ClientAnchor anchor = helper.createClientAnchor(); //sheet.setColumnWidth(1, sheet.getColumnWidth(0) *2); anchor.setCol1(1); anchor.setRow1(1); anchor.setCol2(2); anchor.setRow2(2); Picture pict = drawing.createPicture(anchor, pictureIdx); String file = "picture.xls"; if(wb instanceof XSSFWorkbook) file += "x"; FileOutputStream fileOut = new FileOutputStream(file); wb.write(fileOut); fileOut.close(); Regards A -----Original Message----- From: Avinash Kewalramani [mailto:[email protected]] Sent: Thursday, March 19, 2009 5:04 PM To: POI Users List Subject: RE: Writing html code to xls cell Hi This is sort of related to this thread.I just want to create a hyperlink on a imagein a cell. Excel allows it but there is no example or api method I canfind that does thatHere is the code I have and it does not create hyperlinks on images. Mark talked about icons with links. how do you do that Mark with XSSF?I could use the same idea for images as hyperlinks. Thanks for any pointers. Regards A -----Original Message----- From: MSB [mailto:[email protected]] Sent: Thursday, March 12, 2009 10:44 AM To: [email protected] Subject: Re: Writing html code to xls cellThe problem - at least to my mind - that you face, is that you wish toplace a rendered copy of the html markup into a cell; and it is the 'rendering'part of the problem that is the real stumbling block. The only way thatIcan think of to accomplish this is to use something like IE or Firefoxtoopen the html and generate a rendered page, then grab an image and savethataway as a bmp or jpg - I cannot remember which one can be placed onto a spreadsheet offhand sorry - then you could position the image onto anExcelspreadsheet. Even then, I do not think that you can guarantee that each image will occupy a single cell. Furthermore, I think that you willface just the same sorts of issues with .doc or Rich Text Format files, because both include the content - the text, tables, pictures, etc - and formatting information.Could you not look at modifying what you want to do? I know that it is possible to place hyperlinks into cells, what I do not know is whetheryoucould create an icon that sort of resembles the document you want toopen,place that in the cell, mark it as a hyperlink and link to the originalfilesuch that if the user clicks on the icon the file is opened using thedefault application for that file type; Word for .doc and .rtf (propably), IE or Firefox for html files and so on. Aside from that, I am out of ideas, sorry. Satish HS wrote:Dear MSB,Thanks again. Yes, My requirement is to write a complete html page toonesingle cell. However, if that is not possible, I would like to know ifthereis any way to write a complete .doc file or any RTF file to a singlecell? Or any other swing component that I can use for rich text editing whosecontent can be exported to a single cell retaining all the format?Thanks for your help. I hope you don't mind me asking further. Thanks, Satish HSOn Thu, Mar 12, 2009 at 3:23 AM, MSB <[email protected]> wrote:Have you changed the requirement or are you saying that you want toopen an html file, parse the markup, render a complete page so that it resembles thesort of display you would see in a browser,and then write that pageinto asingle cell of an Excel spreadhseet? If so, then the answer is no,sorry. Ido not have the ability, skills or time to create what amounts to abrowser. Satish HS wrote:Thanks for the response. I truly appreciate it. Regarding yourquestionabout the font and size, it will be specified in the html code.Myactualneed is to populate each cell with separate html-files. So, eachcellcorresponds to a html-file. I already have the java code which stores the html code in textfile(s),how can I populate each cell with separate file.Can I do this with your solution of using Desktop class? Can yousendme asmall code snippet of it, if its not too much to ask. Thanks, Satish HS On Wed, Mar 11, 2009 at 2:19 PM, MSB <[email protected]>wrote:Right, now I understand. You want HSSF to parse html markup foryou.The short answer to your question then is no, it cannot do this.Youwillhave to create a tool to parse the html and extract the informationfromthemarkup to create the cells. As an example of what I mean, what fontandwhat size should HSSF use to render the example you gave?Just a simple question, why do you want to use HSSF to populate anExcelspreadsheet in this manner? Did you know that you can use Excel toopenanhtml file and that it - Excel that is - can parse the markup andrenderthepage for you? A short way around your problem would be to use Javatocreatea text file containing the html code and then ask it to start Excelforyou using the Desktop class. Satish HS wrote:Alright, here is my need, My input is a html String as below: String str = "<html>Some word</html>"; How do I pass this on using the API to Excel Cell, I want theexcelcellto display "Some word" in italic.The actual need is not just to display the italic but to supportalltypesof html (rtf, background color, font, including images etc..) I hope it is clear now, please let me know if you any doubts. Regards, Satish HSOn Wed, Mar 11, 2009 at 3:56 AM, MSB <[email protected] >wrote:cell-- View this message in context:http://www.nabble.com/Writing-html-code-to-xls-cell-tp22441551p22461389.htmlSent from the POI - User mailing list archive at Nabble.com.---------------------------------------------------------------------To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]-- View this message in context: http://www.nabble.com/Writing-html-code-to-xls-cell-tp22441551p22471025.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]-- View this message in context: http://www.nabble.com/Writing-html-code-to-xls-cell-tp22441551p22481814.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]-- View this message in context: http://www.nabble.com/Writing-html-code-to-xls-cell-tp22441551p22615547.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]-- View this message in context: http://www.nabble.com/Writing-html-code-to-xls-cell-tp22441551p22675874.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
