javaexcelapache-poiclipboardspreadsheetml

Decode XML Spreadsheet content of a clipBoard generated by Excel


I want to do a very simple thing in my program :

When a user do a copy of a selection in Excel (2007 - 2016), I want to be able to read the clipboard content, then extract all the values.

Currently Excel puts into the clipboard lots a different formats like Biff5, Biff8, CSV, plain/text etc.

One simple solution could be to use the CSV format but that's not precise enough because if I tumble on a number, I wouldn't know if it was a String or a number in the excel file. Also the dates are sent in their original format and it will be a pain to understand it.

So the solution I see is to parse the "XML Spreadsheet" sent by Excel which looks like that :

 <?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Feuil1">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="3"
   ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
   <Row>
    <Cell><Data ss:Type="Number">8</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">9</Data></Cell>
   </Row>
   <Row>
    <Cell ss:Formula="=SUM(R[-2]C:R[-1]C)"><Data ss:Type="Number">17</Data></Cell>
   </Row>
  </Table>
 </Worksheet>
</Workbook>

Before you ask, I've considered POI. But as far as I understood I need to use XSSF. But to use that I need poi-ooxml, and to use that I need poi-ooxml-schemas and poi. I don't know the total weight of these JARs but I'm not keen on the fact to add 10Mb of jars just to extract an information from a clipBoard.

Has anyone ever tried to do that? Is there a project that could do that?


Solution

  • The code to resolve the issue can be found here :

    https://github.com/Maxoudela/XMLSpreadsheetParser