Why did you implement a different behaviour in XSSFWorkbook and HSSFWorkbook?

Jul 4, 2014 at 3:56 AM
BackgroundColor setting, rows shifting, merged reagion creating and many other things has diifferent behaviour in the different IWorkbook implementations. When I work with interface I expect the same reaction from its implementaion. Why didn't you hide Excel features behind IWorkbook implementations?
Coordinator
Jul 4, 2014 at 4:05 AM
Can you give me some detailed examples? The behavior should be same or almost same.
Jul 4, 2014 at 9:37 AM
For example, setting background color. For the HSSFWorkbook item:
                HSSFWorkbook workbook = ... // getting workbook
                ...
                var pallete = workbook.GetCustomPalette();
                var color = pallete.FindSimilarColor(_backgroundColor.R, _backgroundColor.G, _backgroundColor.B);
                if (color != null)
                {
                    var colorIndex = color.GetIndex();
                    _poiCell.CellStyle.FillBackgroundColor = colorIndex;
                }
And for the XSSFWorkbook item:
            XSSFCellStyle style =... // getting cells style
            ...
            style.FillBackgroundXSSFColor = new XSSFColor(_backgroundColor);
            style.FillPattern = FillPattern.SolidForeground;
Coordinator
Jul 6, 2014 at 6:56 AM
For HSSFWorkbook, you can also use CellStyle, FillPattern and FillForegroundColor. Why do you use custom pallette in HSSF? I don't understand.
Any other examples?
Jul 7, 2014 at 5:17 AM
Edited Jul 8, 2014 at 4:06 AM
tonyqus wrote:
For HSSFWorkbook, you can also use CellStyle, FillPattern and FillForegroundColor.
Good news. Thank you.
tonyqus wrote:
Why do you use custom pallette in HSSF? I don't understand.
I use it because I read it in the docs: http://poi.apache.org/spreadsheet/quick-guide.html#CustomColors. However, the type of FillForegroundColor property is short. How can I convert C# Color value to set FillForegroundColor property using IWorkbook interface only?

tonyqus wrote:
Any other examples?
In the next example:
            var region = new CellRangeAddress(RowIndex, RowIndex + RowSpan - 1, ColIndex, ColIndex + ColSpan - 1);
            _regionIndex = _cell.Sheet.AddMergedRegion(region)
HSSDSheet.AddMergedRegion(region) returns 0 and XSSDSheet.AddMergedRegion(region) returns 1 in the same situation.
Coordinator
Jul 8, 2014 at 5:26 AM
It's just a increasing region index. It's possible that there are many regions so that this method will return 0, 1, 2, 3. It's normal.
Jul 8, 2014 at 5:34 AM
Edited Jul 8, 2014 at 5:35 AM
tonyqus wrote:
It's just a increasing region index. It's possible that there are many regions so that this method will return 0, 1, 2, 3. It's normal.
Of course It's normal to increasing index. It's not normal to start from zero in HSSDSheet.AddMergedRegion(region) and from 1 in XSSDSheet.AddMergedRegion(region).
And you didn't answer about converting Color to short.