Can you provide a test case, sample code, or full stacktrace? How is the new sheet created? It looks to me from the code that the message means exactly what it says - the style you are trying to set and the cell you are trying to set it on come from different Workbook objects. Both the style and the cell hold a reference to the StylesTable object read from (or created for) the Workbook in which they are found. POI doesn't support directly assigning styles across Workbook instances. See this thread[1] for a description of why, and what to do instead when you need to copy a style between workbooks.
Greg [1] https://stackoverflow.com/questions/10773961/apache-poi-apply-one-style-to-different-workbooks On Thu, Dec 20, 2018 at 11:58 AM Rob Sargent <robjsarg...@gmail.com> wrote: > I'm using 4.0.1 as of this morning hoping this would help. I have > recently begun to get: > > Exception in thread "main" java.lang.IllegalArgumentException: This > Style does not belong to the supplied Workbook Styles Source. Are > you trying to assign a style from one workbook to the cell of a > different workbook? > at > > org.apache.poi.xssf.usermodel.XSSFCellStyle.verifyBelongsToStylesSource(XSSFCellStyle.java:121) > at > org.apache.poi.xssf.usermodel.XSSFCell.setCellStyle(XSSFCell.java:667) > > and I am adding style to a cell in a new sheet, same workbook. The > immediate code is not new and had been working (in 4.0.0). Not sure what > change I made has caused this to start. > > I confess the original xlsx has been touched by LibreOffice/Calc and > saved as xlsx. Linux file command reports: > > file '/home/u0138544/tools/reform/Compicated Query for Rob Tool.xlsx' > /home/u0138544/tools/reform/Compicated Query for Rob Tool.xlsx: > Microsoft OOXML > > Any suggestions appreciated. > > >