I have an Excel sheet in which 2 columns have a dropdown with one about 4-5
values and the other with 2 values that can be selected. I would like to read
the value that is there for each row in these two columns. . What is the code
sample to do that? I did browse a while on the net and this forum, but did not
find any answers. I posted in the JExcel Yahoo groups , but no success.
I have added the following code, but this does not help. This code sample just prevents the "common Assertion failed" error
WorkbookSettings settings = new WorkbookSettings();
settings.setSuppressWarnings(true);
Workbook workbook = Workbook.getWorkbook(sis, settings);
The sheet gives an erroneous row count when the dropdown is there. Has anyone been able to read the values selected in the drop down ?
If you have applied an autofilter to your Excel sheet then probably that is responsible for the issue. I would suggest you to please remove the autofilter and then try fetching the value of the combobox.
Cell yourCell = yourSheet.getCell(x,y);
String comboboxValue = yourCell.getContents();
logger.log("value selected in combobx is : " + comboboxValue );
Related
I am trying to add few images to excel sheet manually. After that I have to read those images in java code using aspose cells library. I can read using aspose as below.
Workbook book = new Workbook("test\\output.xlsx");
WorksheetCollection collection = book.getWorksheets();
Worksheet worksheet = collection.get(0);
PictureCollection pics = worksheet.getPictures();
System.out.println("Total number of pictures in the sheet : "+pics.getCount());
for(int i=0; i<pics.getCount(); i++) {
Picture pic = pics.get(i);
System.out.println("Name of the image at index "+i+" is "+pic.getName());
}
But I have an excel sheet as below in which I added images manually.
I have to read it to a HashMap such that key will be the Code column values and values will the image column values. I want proper correspondence. Since images are not cell based I could not get the Map in that way. So is there any way I can map proper 'Code' column value with proper 'Images' column value.
Thank you in Advance.
I'm having a problem evaluating excel sheet cell which uses named cell in its formula. I'm using apache-poi version 3.17, java 1.8 and the file I'm working with is .xlsm. Here is an example code:
//Getting the excel file from the database
Document doc = documentRepository.findByDocumentType(DocumentType.EXAMPLE);
InputStream fis = new ByteArrayInputStream(doc.getFileData());
Workbook wb = new XSSFWorkbook(fis);
Sheet mappingSheet = workbook.getSheet("Quote services");
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// This cell contains a formula which uses named cell
CellReference cellReference = new CellReference("A109");
Row row = mappingSheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
CellValue cellValue = evaluator.evaluate(cell);
This gives me the following error:
org.apache.poi.ss.formula.FormulaParseException: Specified named range
'Discount' does not exist in the current workbook.
The excel formula looks something like that:
=Discount*A7
Where Discount is A5 and if I change the formula to look like this:
=A5*A7
it works fine.
This is kind of strange cause if I try to get the named field Discount it finds it, but if I use evaluate on a cell which uses the field it doesn't.
The document is predefined so I can't change anything in it. If I name the given discount cell with poi and with the same name there is no problem, but I don't want to do this cause there are more named fields in the document and if something change I have to change the code. Any help will be appreciated!
I found the problem! It was that the Discount field was referenced from a hidden sheet in the document and it was referenced like this: Discount instead of 'Quote services'!Discount.
Are you sure that Discount is indeed within the Workbook that you are evaluating? The message is pretty clear.
Can you show exactly how the formula looks like - is it something like this:
=SUM('C:\Data\[Finances.xlsx]Discount'!D10:D25)
Try setIgnoreMissingWorkbooks(true), and if it works, then the Discount is set in another workbook. setIgnoreMissingWorkbooks.
I am trying to retrieve a value from a cell in excel but it is merged. I am using Java
This is what i have:
ByteArrayInputStream bxf = new ByteArrayInputStream(entity.getAttachment().getFile());
Workbook wb = WorkbookFactory.create(bxf);
Sheet sheet = wb.getSheetAt(0);
Row cpRow = sheet.getRow(4);
Here is the example of the excel:
Red Block is a merged cell :
edit
I am using apache.poi library
Reason why you getting a null pointer are that the value you are looking at currently is the actual row 5 on sheet.
As stated by #Berger in the comment the 'getRow is 0 based'
Use getRow(3) instead.
Please see https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html
aswell as
it states https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html
HSSFRow getRow(int rowIndex)
Returns the logical row (not physical) 0-based.
I'm trying out Google Sheets API from a Java application. I've accessed the file mentioned in the tutorial but I cannot access any file that I have created on my own.
This is the code I'm using:
String spreadsheetId = /*omitted*/;
String range = "Class Data!A1:B";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
I created a spreadsheet manually in Drive, filled A1:B with strings and copied the id from the URL, looking something like "1IeoY5jY3Su86x1uvgc1yJqEEU-6dd6FdUKo8Yf5J73k" (not an actual ID).
This generates an error 400 Unable to parse range: Class Data!A1:B
I'm guessing that this means that it cannot access my spreadsheet, since the sheet is filled with strings "ab" in these cells.
The sample code has a spreadsheetId that refers to some kind of public document and it is working for that document. I am guessing that I am doing something fundamentally wrong here. I have verified that the document is created with the same credentials as the ones I'm using for the Java application. Any ideas?
Class Data is the name of the sheet in the sample sheet. You should substitute that with the name of the sheet in your spreadsheet. You can see the name of the sheet on the tab near the bottom of the screen. It defaults to Sheet 1.
A1:B is the number of rows and columns to read. It is saying to read all data in columns A and B from rows 1 to the last row. You should swap that with the rows and columns you want to read in your sheet.
Am inserting a worksheet to Google spreadsheet every week with the help of following command
WorksheetEntry worksheet = new WorksheetEntry();
worksheet.setTitle(new PlainTextConstruct(sheet_name));
worksheet.setColCount(data[0].length);
worksheet.setRowCount(data.length);
URL worksheetFeedUrl = entry.getWorksheetFeedUrl();
service.insert(worksheetFeedUrl, worksheet);
Always its inserting the sheet at last position but i want to insert it at the second position every time....
Is it possible using java? If so please help me...
Thanks in advance...
It is possible with google-apps-script, but not with the spreadsheet API (GData).
insertSheet(sheetIndex)
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#insertSheet(Integer)
Inserts a new sheet in the spreadsheet at the given index. As a side effect, it makes it the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet(1);
AFAIK, there is no such function with the spreadsheet API (GData). It is not listed here https://developers.google.com/google-apps/spreadsheets/