0

Extract selected celldata values programmatically in keikai (Excel)

asked 2021-08-20 23:02:45 +0800

bztom35 gravatar image bztom35
103 4

updated 2021-08-21 05:13:12 +0800

I am trying to extract the selected cell data programmatically in KeiKai Excel. I have no clue where to begin and any advice will be appreciated.

//selected rows from a column and extract all the celldata values programmatically.
Range src = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-23 16:27:44 +0800

cor3000 gravatar image cor3000
6094 2 7
ZK Team

updated 2021-08-24 11:14:07 +0800

Looks like you almost got there, once you have the range you're interested in you can call getCellValues() to get the values of each cell in a linear list. (Assuming that's what you mean by 'extract' - if you had something else in mind please add the missing details).

Range src = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
List<Object> cellValues = src.getCellValues();
System.out.println("values for region " + src.toString() + " : " + cellValues);

will print something like this:

values for region Sheet1!B5:D6 : [34.0, true, 324.0, ert, null, 40302.0]

UPDATE 2021-08-24:

before keikai 5.5.0 you have to iterate over the range cells in a loop:

Range src = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
int rowCount = src.getRowCount();
int columnCount = src.getColumnCount();
List<Object> cellValues = new ArrayList<>(rowCount * columnCount);
for(int row = 0; row < rowCount; row++) {
    for(int col = 0; col < columnCount; col++) {
        cellValues.add(src.toCellRange(row, col).getCellValue());
    }
}
// List<Object> cellValues = src.getCellValues(); // since keikai 5.5.0 (EE)
System.out.println("values for region " + src.toString() + " : " + cellValues);
link publish delete flag offensive edit

Comments

This makes sense because I was using the OSE 5.0 version of the KeiKai and it didn't have this new method(getCellValues) in the later version of the EE.

bztom35 ( 2021-08-24 00:06:13 +0800 )edit

that clarifies, I updated the response above with an OSE compatible version

cor3000 ( 2021-08-24 11:14:55 +0800 )edit

Thanks Cor3000!

bztom35 ( 2021-08-24 23:49:33 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2021-08-20 23:02:45 +0800

Seen: 7 times

Last updated: Aug 24

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More