firegloves / MemPOI

A library to simplify export from database to Excel files using Apache POI :japanese_goblin:
MIT License
57 stars 7 forks source link

withColumnName() working only with uppercase column names #54

Closed apoorva-sriv closed 1 year ago

apoorva-sriv commented 2 years ago

I have a select Name from Table query. When I use .withColumnName("Name").withColumnDisplayName("First Name"), Name is still the header in Excel. I need to use .withColumnName("NAME") to make it display First Name. Shouldn't it be case-insensitive and work in the first case too? (It's the same with both XSSFWorkbook and SXSSFWorkbook.)

firegloves commented 2 years ago

@apoorva-sriv yes it should be case insensitive. Can I ask you to double-check which is the resulting column name from the result set by manually printing it? I suspect that the issue could derive from there

apoorva-sriv commented 2 years ago

The result set has Name only.

firegloves commented 2 years ago

@apoorva-sriv I tested your case and I can't reproduce the issue. This is what I did:

PreparedStatement prepStmt = connection.prepareStatement("SELECT * FROM MEMPOI.MYTABLE");

Workbook wb = new SXSSFWorkbook();

MempoiColumnConfig mempoiColumnConfig = MempoiColumnConfigBuilder.aMempoiColumnConfig()
                    .withColumnName("Name")
                    .withColumnDisplayName("First Name")
                    .build();

MempoiSheet mempoiSheet = MempoiSheetBuilder.aMempoiSheet()
                    .withPrepStmt(prepStmt)
                    .addMempoiColumnConfig(mempoiColumnConfig)
                    .build();

The resulting file contains the expected "First Name" string as the column header. Please double-check if Oracle automatically capitalized the whole column name, I'm quite sure that this is the problem.

Otherwise please provide me with a way to reproduce your issue

apoorva-sriv commented 2 years ago

Please double-check if Oracle automatically capitalized the whole column name, I'm quite sure that this is the problem.

Yes, this might likely be the problem, and you couldn't reproduce it because you "forced the NAME field to be Name (pascal case)", but that's why I raised the issue here: if both select Name and select NAME work in Oracle, then shouldn't both work with MemPOI too? Would it be a good idea to add a case with toUpperCase inside the definition of withColumnName?

firegloves commented 2 years ago

@apoorva-sriv I thought a bit about your request, but I'm not sure of proceeding with this implementation.

The case sensitiveness must be kept in order to support the various cases and this is a certainty.

We could add the toUpperCase as you suggest, but is it really needed? I would like to avoid increasing the code complexity if it isn't a requirement, can't we achieve the same goal by adding the right column name in the column configuration?

Am I missing something that prevent you from proceeding in this way?

apoorva-sriv commented 2 years ago

No, it's not blocking anything. I just thought it might help make the library more intuitive since, if it works with SQL, one might expect it would work here too.