abap2xlsx/ZA2X/CLAS
chrassig 55ac5af43b More sophisticated calculation of cell widths
Let me start by saying we really love the ABAP2XLSX project. Compared to exporting CSV files and importing them to Excel, it makes transferring data from SAP systems to Excel and vice versa so much easier.

What we did not like so far was the optimization of column width, especially because of the way this is realized in the XLSX file format (why did they not just add an attribute "optimize column width = true"?). Anyway, ABAP2XLSX being an open source project, we decided to try to bring some progress to this feature.

We ended up rewriting the method CALCULATE_CELL_WIDTH of the class ZCL_EXCEL_WORKSHEET.

We added the following features:
a) Before, the calculation of the cell width in ABAP2XLSX did not take into account the fact that Excel uses a proportional font by default. Thus, columns with many "i"s ended up too wide, while columns containing many "W"s ended up not wide enough.

We now use the function module LOAD_FONT, contained in SAP package BC. Thus, it should be available in pretty much every SAP system that runs ABAP. LOAD_FONT returns an internal table containing the width of every letter known in a font. You can upload Excel's default font Calibri using transaction SM73. Make sure to upload all four files (standard, bold, italic, bold and italic) and to use the description "Calibri", i.e. exactly the name Excel displays for the font. If you want to use other fonts in your files created by ABAP2XLSX, you can of course upload other fonts as well.

We calculate the sum of the widths of all characters in a cell, and add some cell padding, similar to the way Excel does it. If the font is not available in your SAP system, we revert back to a logic similar to the old one.

As calling LOAD_FONT for every cell took several seconds when we tested with larger tables, we store the values read from the function in a hash table. Thus, we only have to call the function once for every combination of font name and font attributes used in your Excel file.

b) XLSX stores dates in a cryptic format. For dates, the current implementation calculates the width of the cryptic values, thus, the columns end up too narrow.

Fortunately, ABAP2XLSX already contains a method to transform the cryptic value into an ABAP date. We then use ABAP's WRITE statement to create a date in the format the user is preferring, and calculate the width of this formatted date.

c) ABAP2XLSX currently does not consider auto filters. Thus, a column may end up too narrow, not showing the complete header text.

We fixed this by adding a fixed value to the cell width if an auto filter is activated. We use a fixed value because the size of the auto filter button in Excel does not depend on the font size you use.

d) ABAP2XLSX only estimates the width of the characters. Excel adds a small fixed amount to the width of the characters to create some horizontal cell padding. We added cell padding as well, as this brought the cell width even closer to the values calculated by Excel.

e) ABAP2XLSX already uses ABAP's data type FLOAT to store the width of a cell. However, CALCULATE_CELL_WIDTH used data type I (integer) to calculate the cell width before. Changing the parameter type for the parameter EP_WIDTH from I to FLOAT, and adjusting the variable used by the calling method CALCULATE_COLUMN_WIDTHS in the same way, made the calculation even more precise.
2014-03-14 16:15:09 +01:00
..
ZCL_EXCEL_AUTOFILTER.slnk Ready to test #259 Fix in classes ZCL_EXCEL_AUTOFILTERS, ZCL_EXCEL_AUTOFILTER, ZCL_EXCEL_WORKSHEET, ZCL_EXCEL_WRITER_2007 and ZCL_EXCEL_CONVERTER 2013-04-07 10:06:59 +00:00
ZCL_EXCEL_AUTOFILTERS.slnk Ready to test #259 Fix in classes ZCL_EXCEL_AUTOFILTERS, ZCL_EXCEL_AUTOFILTER, ZCL_EXCEL_WORKSHEET, ZCL_EXCEL_WRITER_2007 and ZCL_EXCEL_CONVERTER 2013-04-07 10:06:59 +00:00
ZCL_EXCEL_COMMON.slnk #284: Added support of reading XLSX-Files where the formulae are not stated explicitly but by reference to another cell holding a reference formula. Thanks to David for supplying the method to shift a formula to another cell. 2013-08-11 10:43:02 +00:00
ZCL_EXCEL_CONVERTER_ALV_GRID.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER_ALV.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER_RESULT_EX.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER_RESULT_WD.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER_RESULT.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER_SALV_TABLE.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CONVERTER.slnk Fixed #287 issue. Correct some old problems with langu="1" and add new functions as options for converter: 2013-08-11 18:48:00 +00:00
ZCL_EXCEL_CUSTOMUI_BUTTON.slnk Macro-Enabled workbook issue #89 2011-06-02 09:23:58 +00:00
ZCL_EXCEL_CUSTOMUI.slnk Macro-Enabled workbook issue #89 2011-06-02 09:23:58 +00:00
ZCL_EXCEL_DATA_VALIDATION.slnk Enhanced ZCL_EXCEL_DATA_VALIDATION and ZCL_EXCEL_WRITER_2007 to fix issue #54. Adjusted demo report ZDEMO_EXCEL9 to show the new features. New data elements for validation error style and validation operator. Incompatible change of the attribute value attribute of class ZCL_EXCEL_DATA_VALIDATION to formula1. 2011-02-17 23:47:45 +00:00
ZCL_EXCEL_DATA_VALIDATIONS.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_DRAWING.slnk Fix issue #308 2014-03-13 12:16:32 -05:00
ZCL_EXCEL_DRAWINGS.slnk Ready to test #204 #187 #188 2012-08-26 16:28:49 +00:00
ZCL_EXCEL_GRAPH_BARS.slnk #240 Charts + Daily build including all developments 2012-12-06 16:48:27 +00:00
ZCL_EXCEL_GRAPH_LINE.slnk #240 Charts + Daily build including all developments 2012-12-06 16:48:27 +00:00
ZCL_EXCEL_GRAPH_PIE.slnk #240 Charts + Daily build including all developments 2012-12-06 16:48:27 +00:00
ZCL_EXCEL_GRAPH.slnk #240 Charts + Daily build including all developments 2012-12-06 16:48:27 +00:00
ZCL_EXCEL_HYPERLINK.slnk Issue #155 - less strict typing of parameters. This time: ip_column set from ZEXCEL_CELL_COLUMN_ALPHA to SIMPLE 2012-04-02 14:10:16 +00:00
ZCL_EXCEL_LEGACY_PALETTE.slnk Fix #92 - Enable changing legacy color palette (to change colors on Excel ver <= 2003) 2011-07-11 21:51:08 +00:00
ZCL_EXCEL_PROPERTIES.slnk Macro-Enabled workbook issue #89 2011-06-02 09:23:58 +00:00
ZCL_EXCEL_RANGE.slnk issue #235 - Prepared Reader and Writerclass for handling of repeat rows/columns 2012-12-02 09:46:47 +00:00
ZCL_EXCEL_RANGES.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_READER_2007.slnk Add extraction of data validations 2014-03-04 22:26:54 +01:00
ZCL_EXCEL_READER_HUGE_FILE.slnk Renaming huge file reader class 2014-02-24 15:32:29 -06:00
ZCL_EXCEL_READER_XLSM.slnk ready to test #232 2012-11-11 09:36:28 +00:00
ZCL_EXCEL_SECURITY.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_SHEET_SETUP.slnk Implemented fixes for issue #145 Sheet / Page Header and Footer including placeholders for pagenumber, date etc. 2012-03-15 22:27:51 +00:00
ZCL_EXCEL_STYLE_ALIGNMENT.slnk Workbook protection 2010-09-23 21:43:41 +00:00
ZCL_EXCEL_STYLE_BORDER.slnk Enhancement to border style. DEMO2 update 2011-05-12 19:33:25 +00:00
ZCL_EXCEL_STYLE_BORDERS.slnk re #93 - read cell alignment and diagonal borders 2011-05-13 21:29:25 +00:00
ZCL_EXCEL_STYLE_COLOR.slnk Fix #86 - add support for all Excel coloring options - standard color themes, indexed colors and tint 2011-05-04 21:52:43 +00:00
ZCL_EXCEL_STYLE_CONDITIONAL.slnk Databar Conditional Formatting by Albert Lladanosa 2013-10-31 21:05:10 +00:00
ZCL_EXCEL_STYLE_FILL.slnk Fix #86 - add support for all Excel coloring options - standard color themes, indexed colors and tint 2011-05-04 21:52:43 +00:00
ZCL_EXCEL_STYLE_FONT.slnk ready to test #120 2011-12-07 23:35:11 +00:00
ZCL_EXCEL_STYLE_NUMBER_FORMAT.slnk ready to test 2012-06-30 19:49:06 +00:00
ZCL_EXCEL_STYLE_PROTECTION.slnk Workbook protection 2010-09-23 21:43:41 +00:00
ZCL_EXCEL_STYLE.slnk Ready to test #139 2012-03-19 21:46:37 +00:00
ZCL_EXCEL_STYLES_CONDITIONAL.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_STYLES.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_TABLE.slnk Fix issue #296 2014-03-05 14:03:43 -06:00
ZCL_EXCEL_WORKSHEET_COLUMNDIME.slnk Issue #157, 2nd topic:Allow default styles for columns, sheet or whole document 2012-04-04 22:03:54 +00:00
ZCL_EXCEL_WORKSHEET_ROWDIMENSI.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@285 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2012-03-29 20:29:00 +00:00
ZCL_EXCEL_WORKSHEET.slnk More sophisticated calculation of cell widths 2014-03-14 16:15:09 +01:00
ZCL_EXCEL_WORKSHEETS.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@3 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2010-09-14 08:05:50 +00:00
ZCL_EXCEL_WRITER_2007.slnk Fix for issue #301 2014-03-05 13:50:07 -06:00
ZCL_EXCEL_WRITER_CSV.slnk Fix issue #113 2011-09-25 10:29:04 +00:00
ZCL_EXCEL_WRITER_XLSM.slnk ready to test #205 2012-10-14 13:25:03 +00:00
ZCL_EXCEL.slnk git-svn-id: https://subversion.assembla.com/svn/abap2xlsx/trunk@374 b7d68dce-7c3c-4a99-8ce0-9ea847f5d049 2012-12-01 17:42:22 +00:00
ZCX_EXCEL.slnk Exception class is no longer marked as final 2014-02-24 15:07:13 -06:00