Thank you for this, really good piece of work and I was wondering if you
would be willing to post it as an example on the POI website so that others
can see how to perform this operation? If you do not have the time, I would
be quite willing to work it up into an example and post the code here before
submitting it to the website; and it goes without saying that you would be
credited as the author.

Yours

Mark B


MerlinCristi wrote:
> 
> Update
> 
> After some time I found the solution. And it is like this
> 
> XSSFWorkbook wb = new XSSFWorkbook();
> XSSFSheet s = wb.createSheet("Sheet1");
> XSSFRow r;
> XSSFCell c;
> CTRowImpl ctr;
> r = s.createRow( 0);                          
> c = r.createCell( 0);
> c.setCellStyle( timeblockLabel);              
> c.setCellValue( "Some Text");
>       
> c = r.createCell( 1);
> c.setCellStyle( timeblockLabel);
>               
> c = r.createCell( 2);
> c.setCellStyle( timeblockLabel);
>               
> ctr = (CTRowImpl) r.getCTRow();
> List spans = new ArrayList();         
> Object o = "1:3";
> spans.add( o);
> ctr.setSpans( spans);
>               
> String filename = "workbook1.xlsx";    
> FileOutputStream out = new FileOutputStream(filename);
> wb.write(out);
> out.close();
> 
> and
> 
> timeblockLabel.setAlignment( XSSFCellStyle.ALIGN_CENTER_SELECTION);
> 
> I tested and it works fine. The label is centered over selection.
> If you decide to span something over cell 1,2,3 for example cell 1, 2, 3
> must exist.
> 
> Enjoy, 
> Cristian
> 
> 
> MerlinCristi wrote:
>> 
>> Hi. I made one xlsx file with some cells selected and saved. After that I
>> loded with poi and
>>  if you call this code
>> 
>> InputStream myxls = new FileInputStream("ex1.xlsx");
>> XSSFWorkbook wb     = new XSSFWorkbook(myxls);       
>> XSSFSheet s = wb.getSheetAt( 0);
>> XSSFRow r = s.getRow(0);
>> CTRowImpl cr = (CTRowImpl) r.getCTRow();
>> 
>> the content of cr is
>> 
>> <xml-fragment r="1" spans="1:3" x14ac:dyDescent="0.25"
>> xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships";
>> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006";
>> xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac";
>> xmlns:main="http://schemas.openxmlformats.org/spreadsheetml/2006/main";>
>>   <main:c r="A1" s="1" t="s">
>>     <main:v>0</main:v>
>>   </main:c>
>>   <main:c r="B1" s="1"/>
>>   <main:c r="C1" s="1"/>
>> </xml-fragment>
>> 
>> You can see in the first row attribute spans="1:3"
>> 
>> Also if you call cr.getSpans() you will get the list of spans, in my case
>> 1:3. But I am unable to edit this list. There is a method setSpans and it
>> requires a parameter of type XMLSimpleList but I am unable to add values
>> to this list.
>> 
>> Probably it is possible to somehow edit this values from java but it
>> seams to be rocket science.
>> 
>> I am waiting for some replay regarding this issue.
>> 
>> Cristian
>> 
>> MSB wrote:
>>> 
>>> Well, there is an option to center - no, pre Webster so it ought to be
>>> centre - the cells contents across a selection in the CellStyle class
>>> just as there is in Excel, but like you, I cannot see how to obviously
>>> make use of it. Currently, I am thinking about trying to use the ability
>>> to create a name to see if that will help but I cannot be sure.
>>> 
>>> Do you know in advance which cells need to be treated in this way? If
>>> so, you could create a template that POI would then be able to open and
>>> populate with data. Secondly, if you do know which cells are to be
>>> treated in this way, you could create styles on another sheet in the
>>> workbook and then try applying them to other cells in another sheet of
>>> the same workbook. Again, I do not know if this would work but it should
>>> be quick enough and easy enough to try out.
>>> 
>>> When I get back homw after work today, I will have a play to see what I
>>> can come up with.
>>> 
>>> Yours
>>> 
>>> Mark B
>>> 
>>> 
>>> Cristian Petrula wrote:
>>>> 
>>>> Hi. I have a huge problem. I need to use ALIGN_CENTER_SELECTION over 2,
>>>> 3..
>>>> cells but I am not allowed to merge cells And I don't have any idea how
>>>> to
>>>> simulate cell selection. I saw in xml file attribute "spans" in row
>>>> element.
>>>> Do you know how to use this align style with selected cells?
>>>> 
>>>> Cristian
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/ALIGN_CENTER_SELECTION-question-tp28660795p28669349.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to