I am populating URL into Excel sheet through java code. But the hyperlink is not enabled if I populate through Java code.
If I type URL into Excel sheet directly, hyperlink automatically coming. Could you please let me know why it is not coming if I populate through code.
You may need Worksheet_followhyperlink enabled in the spreadsheet through vba. I've encountered this populating hyperlinks into Excel before. Pop this into the sheet with the links:
Private Sub Worksheet_followhyperlink(ByVal Target As Hyperlink)
Application.EnableEvents = True
Target.Follow
' Any other code you might need.
End Sub
Related
How to do ctrl+f in webdriver/java? I have to do in a way where there are 2 excel sheets, each excel sheet contains list of email addresses. So need to copy each cell email, and search it in a web page. If it finds that email address in the web page then copy the corresponding data and save it in another excel sheet.
I know how to do ctrl+f5 using web driver, but ctrl+f is littly tricky. Any help is appreciated.
You can do it by using the Keys.chord() method:
driver.findElement(By.xPath("your-xpath")).sendKeys(Keys.chord(Keys.CONTROL, "f"));
or by using the Action class and the unicode representation:
Actions action = new Actions();
action.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0066')).perform();
For a full list of unicode characters read more here.
if(driver.findElement(By.XPath("//tagname[text()='mailID']")).isDisplayed){
// write your code
}
or
if(!driver.findElements(By.XPath("//tagname[text()='mailID']")).isEmpty){
// write your code
}
I am exporting an Excel sheet using NatTable (Eclipse Nebula). It contains an image in the header layer and some text in the header as well as body. Here is the code for configuration:
ImagePainter bgImagePainter = new ImagePainter(getImg());
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, HeaderLayout.overImg);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, HeaderLayout.overImg);
Also, I use ExcelExporter to export the data to an Excel Workbook.
I don't know where the error could be, because the text in all other columns is displayed perfectly. If you need to look at any other code snippet, I will update it.
I don't see the what the "error" could be, since you are not telling what your issue is. But I suppose your question is why the image is not exported. And AFAIK the reason is that the NatTable exporter does not support exporting of images at the moment.
I am using Apache POI to generate excel sheets (.xls format) and I have used the following code snippet to create Hyperlinks that link to a different sheet in the same document/workbook.
HSSFSheet summarySheet = workbook.createSheet("Target Sheet");
Hyperlink targetLink = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
targetLink.setAddress("'Target Sheet'!A1");
There are more than one sheet that I'm creating and upon clicking the Hyperlink it shows the respective sheet. However, I'm having difficulty in traversing to the different sheets that I have created with the above lines of code. I need to populate those sheets with data from the database but I don't know how to switch between those sheets.
Any help would be appreciated. Please do let me know before you downvote/if there is anything wrong with my question. Thank you!
To get the sheets in existing xls you can use the HSSFWORKBOOK method getSheet("Sheet Name"):
HSSFSheet linkedSheet = workbook.getSheet("Sheet name");
once you have the linked sheet you can add the entries onto it.
I have a word document with checkboxes in it, and I want to determine whether these are ticked or not and use these results with java. I have tried using a WordExtractor with Apache POI but it didn't seem to include the result.
If I save the docx in txt format it replaces each checkbox with a corresponding 0 or 1, which is ideal, but I don't know how to do that programmatically.
Seems that you are looking for FtCblsSubRecord class (I didn't try it):
http://poi.apache.org/apidocs/org/apache/poi/hssf/record/FtCblsSubRecord.html
http://poi.apache.org/apidocs/org/apache/poi/hssf/record/class-use/SubRecord.html
Results of search in google: checkbox site:poi.apache.org
=========================================
By this post seems not to be posible:
http://osdir.com/ml/user-poi.apache.org/2010-10/msg00068.html
Other post talking about this:
What API can add checkbox to MS Word file using Java?
Insert a checkbox in an Excel sheet using Apache POI
I'm currently working on a Java application that uses a template excel file that contains a pivot table.
The template file also has a data sheet that seeds the pivot table. This data sheet is dynamically loaded in the java application through the Apache POI api.
When I open the excel file I must refresh the Pivot table manually to get the data loaded correctly.
Is there any way to refresh the Pivot table with the POI api so I don't have to manually do it?
You can simple activate an option that will refresh the pivot table every time the file is opened.
This Microsoft documentation says :
In the PivotTable Options dialog box, on the Data tab, select the Refresh data when opening the file check box.
It is possible.
In the PivotCacheDefinition, there is an attribute refreshOnLoad that can be set to true. The cache is then refreshed when the workbook is opened. More information here.
In POI this can be done by calling the method setRefreshOnLoad(boolean bool), that takes a boolean as parameter, on a CTPivotCacheDefinition.
EDIT:
The Apache POI now provides the possibility to create pivot tables and the pivot table is refreshed on load as default. Class XSSFPivotTable
This post says you can turn on an option on the pivot table that will cause it to refresh itself automatically every time the workbook is opened:
How can I refresh all the pivot tables in my excel workbook with a macro?
Hopefully this will still be true after you have used Apache POI to refresh or extend the data rows on which the pivot tables are based.
protected void setRefreshPtOnLoad(boolean refreshOnLoad){
List<POIXMLDocumentPart.RelationPart> relationParts = ((XSSFWorkbook) workbook).getRelationParts();
for (POIXMLDocumentPart.RelationPart part : relationParts) {
PackageRelationship relationship = part.getRelationship();
if (relationship.getRelationshipType().contains("pivotCacheDefinition")){
String relationId = relationship.getId();
XSSFPivotCacheDefinition cache = (XSSFPivotCacheDefinition)((XSSFWorkbook) workbook).getRelationById(relationId);
CTPivotCacheDefinition ctCache = cache.getCTPivotCacheDefinition();
ctCache.setRefreshOnLoad(refreshOnLoad);
break; // if only pivot table cache exists in workbook, else - remove *break*
}
}
}
The basic answer to this is no. POI is a document format reader and writer. Updating the Pivot table is an excel engine issue. Sure, another application could try to duplicate the Excel engine behavior here, but that is really going to get ugly. I recommend using Joel's workaround of accessing the excel COM objects over a webservice to get this kind of thing done.
This might work:
XSSFPivotTable pivotTable = pivotSheet.getPivotTables().get(0);
pivotTable.getPivotCacheDefinition().getCTPivotCacheDefinition().setRefreshOnLoad(true);