Displaying table header in multiple page using Aspose words - java

Currently I'm working with exporting reports using Aspose Words in Java. I'm populating table with dynamic data but my main problem is when data reaches next page there is no header in exported docs. How can I get header for all pages in the exported file. Any suggestions will be appreciated.

We can solve this issue in JAVA in the following way:
1.Load the document
Document doc = new Document(getMyDir() + "Table.SimpleTable.doc");
2.Get the first table
Table table = doc.getChild(NodeType.TABLE, 0, true); //i.e. second parenthesis as index of table in doc file
3. Get the rows which is used for heading of table
Row rows = (Row) table.getRows().get(0);//we can set multiple rows as heading by passing it's index
4. set the rows as HeadingFormat = true
rows.getRowFormat().setHeadingFormat(true);

Select the header portion (row/rows) to be repeated in the template.
Right click it. Go to table properties and select row tab where there is a second option as "Repeat as header row at the top of each page".

Related

How can I locate tooltip <a href>tooltip</a> values inside the table using selenium

from this side https://en.wikipedia.org/wiki/China
I need the values of tables at the right side.
How can I get this?
I stored the header values and trying to match the table header and retrieve the column values but showing error.
List<String> search=new ArrayList<String>();
search.add("President");
search.add("Capital");
search.add("Dialing code");
search.add("Currency");
search.add("Population");
search.add("Official script");
for(int ii=0;ii<search.size();ii++) {
System.out.print("VALUE in search list ; "+search.get(ii));
for(int i=1;i<43;i++) {
String ss=driver.findElement(By.xpath("//*[#id=\"mw-content-text\"]/div/table[1]/tbody/tr["+i+"]/th[1]")).getText();
System.out.println(" VALUE in ss ; "+ss+" tr["+i+"]");
if(ss.toLowerCase().contains(search.get(ii).toLowerCase())) {
System.out.println("value matched");
//WebElement web= driver.findElement(By.xpath("//*[#id=\"mw-content-text\"]/div/table[1]/tbody/tr["+i+"]/td/a"));
//String title=web.getAttribute("title");
//System.out.println(title);
break;
}
}
}
i need to get the href tooltip values of each column like President=Xi jinping,Capital=Beijing,official script=simplified chinese etc.But showing error .Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="mw-content-text"]/div/table[1]/tbody/tr[2]/th[1]"}
If you see the xpath what you are using and the HTML code for the same page what you have given, the first row(tr) of the table is having table header (th) and from the second row onwards, we have table data (td), but not th. That is the reason, you are getting text for 1st index and getting NoSuchElementException from the 2nd index onwards. You can change your xpath in such way to handle where ever table header is there and where table data is there. That will help you to fetch the data.
This xpath (//[#id="mw-content-text"]/div/table[1]/tbody/tr) gives 55 matching elements. If you apply //[#id="mw-content-text"]/div/table[1]/tbody/tr[1], it will match with first element and this element have 'th'. i.e. (//[#id="mw-content-text"]/div/table[1]/tbody/tr[1]/th[1]) will work. But for the 2nd index (//[#id="mw-content-text"]/div/table[1]/tbody/tr[2]), we have td instead of th. There is a problem.
You can change your xptah based on above explanation (I have reviewed HTML for the same and observed some are having th and some are with td. In those cases, fetching all elements data with same xpath is not at all possible. The only possible way is to write the xpath individually or segregate all th's and td's and run the loop with if condition).

PdfBox - Unable to extract some text from pdf

I am trying to extract text from a pdf using pdfbox. However I am unable to extract all the text from a table. See the image below (snipped from the pdf)
(some confidential text has been highlighted)
I am able to get the text out of the 1st table (in orange) and the 3rd table (General Information one). But I am unable to extract anything out of the 2nd table.
In the output I just see a couple of blank lines between the output of 1st and 3rd table.
Here is my code.
PDDocument doc = PDDocument.load(new File("...."));
PDFTextStripper pdfStripper = new PDFTextStripper();
String text = pdfStripper.getText(doc);
System.out.println(text);
doc.close();
Any inputs or suggestions?
I found the issue. The content was being displayed but it was being re-arranged.
The PDF had a couple of tables placed one after the other. The content of this table was being displayed after content of a few tables placed just after it. So for example if I had 6 tables and this was the 2nd table from the top. It's content was being displayed on 5th position instead of 2nd position.
As suggested by Tilman in comments the use of pdfStripper.setSortByPosition(true) results into expected content in expected places.

parsing using JSoup a website - weatherbug

I have tried several approaches (below) and I have not been able to pull out the temperatures from the hourly forecast of weatherbug:
http://weather.weatherbug.com/MA/Boston-weather/local-forecast/hourly-forecast.html?zcode=z6286&zip=02108
I am using JAVA / Jsoup.
The temps are listed as: <span>33° F</span> within a table.
I suspect my problem is not fully understanding the html.
It appears to be within a table labeled: <table cellspacing="0" id="hourly">
Below are several things I have tried with no luck:
It seems like everything I have tried is not able to find or "see" the table.
doc=Jsoup.connect(urlString).get();
dataread = doc.body().text();
length = dataread.length();
System.out.printf("length = %d\n",length);
System.out.println(dataread);
the above was to see if I was at least on track - the data was not in "dataread".
Then I tried printing the results from combinations of:
Elements table = doc.select("table[class=hourly]");
Elements table = doc.getElementsByTag("boxhdr");
Elements byclass = doc.getElementsByClass("boxhdr");
System.out.println(table.size());
System.out.println(table);
I extended my parsing further up the page hoping to get lucky - with the boxhdr label and so forth.
Can you help me extract the temperatures?
Thanks!
The table you want to extract the data from has an id hourly.
Elements table = doc.getElementById("hourly");
Moreover, the content of the table is probably generated by Javascript and it's impossible to retrieve it using Jsoup. Refer to this thread.

Export to XLSX where the page should also contain header

I am using Grails and I am exporting a list of data to the excel sheet.Simple export of table is done, but I need header in that page which consists of a company's logo and the report's title. and the sheet must be saved according to the status of the data which should be in 5 sheets..Also page width must be 11in...
Requirement
5 Sheets:Open,....,closed
Header:
Left side: Logo,
Right side:Report title
So can anyone suggest how to do this!!
Have you tried [header.enabled:true] as one of the formatters?

how to show second page as starting page on load of simple pager in gwt

I selected 5 th record from the second page of datagrid. After some modifications in the selected row i saved it And reloaded the datagrid.I want previous selected row to be selected after reloading also.
Any help can be appreciated.
Assuming that you still have the instance of your DTO that you were editing in your DataGrid you can do following:
// get the start index in the list
int selectedIndex = dataProvider.getList().indexOf(myObj);
// set the visible range
dataGrid.setVisibleRange(selectedIndex,dataGrid.getVisibleItemCount());
// select the row
selectionModel().setSelected(myObj, true); // select the row

Categories

Resources