Print values on printed paper - java

I have 1 bill which contain table, but my requirement is I want to Print values of rows and columns, with correct margin and on correct position. I am using jswing and jTable. Can anyone help me??

If I were you, I would use not a jTable, but something which intended to print: PDF, *.docx, *.rtf. In this way you have full control on page size and orientation and user may simply edit template in his favorite text processor (f.e., if a new blank has the third column 10 mm smaller).
There are many tools for Java to convert in PDF/doc format. I suppose most of them may insert value in specified field on the template.

Related

JXLS 2.0 Conditional Formatting Forumla not updated per row

Trying to create an JXLS excel template where it should be possible to copy conditional formatting from a cell on a specific row to the next generated row.
In the template, I create my formatting. If the value in the cell is equal to "yes" the row should be red.
Template
Conditional formatting
Formula: =$B2="yes"
Applies to: $A$2:$B$2
I know this formula works on an already populated excel sheet here is an example https://trumpexcel.com/highlight-rows-based-on-cell-value/
But when I do this with my excel template and JXLS 2.0 it fails. It copies the formula as it is to each new generated row. So instead of one condition for the whole sheet, there will now be as many as there are rows. The problem here is that it will copy it as is, which means that the formula in each condition will be based on the value in cell C2. So even if cell C3 is generated with the value "no" it will be red, since it is based on the value in C2.
Output excel
Condition Formatting output excel
Any tips on how to solve this directly in the template?
Using
jxls 2.9.0
jxls-poi 2.9.0
One approach is to modify the formula in the template to acheive what we want.
Formula: =INDIRECT("$B" & ROW())="yes"
Description:
ROW() returns the current row number.
"$B" & ROW() gives the cell reference. For example, at row 5, we will get B5
Finally, using INDIRECT(...) we get the value at cell reference and check if is "yes".
Output excel:
What you are experiencing is standard Excel behaviour. In order to achieve what you want you have 2 options: using a regular Range or a dynamic table. I would use the latter.
Using a regular Range
You need to start with at least 2 rows like this:
and then only insert rows after the first row and before the last row. Never before first or after last. The new rows are picking up the same formatting because the underlying range is expanding. For example, inserting 4 rows in between results in:
Using a dynamic table
Assuming you have headers (you don't need to), you select your start range and then format it as a table:
You will have the option to choose if the table has headers or not via a checkbox in the dialog that will appear.
Then you add the same conditional formatting:
The difference now is that when you add a new row, the conditional formatting will automatically expand. The table itself automatically expands so everyting else (formatting, validation, formulas etc.) are expanding with it.
Just make sure you have the auto expanding option on for tables under File/Options/Proofing/AutoCorrect Options/AutoFormat As You Type/Include new rows and columns in table. You can do that programatically as well (I know in VBA you need to set Application.AutoCorrect.AutoExpandListRange to True). The default is True by the way.
No matter how big your table will get, you will have the formatting expanded.

How can I resolve the printing issue for the document that is modified by apache poi

I want to ask a question which is related to apache poi and generated file printing. What I am doing is I am opening a .docx file, inserting some data and saving and printing it.
I am having a file with only 1 table which is something like:
document table
Now, if there are 'n' items, I am generating n-1 rows which copies the format of row 3.
First item is inserted in row 3, if there's another item I am adding a row in the table and saving it likewise I am creating the rows.
Now I want to make this table length = page length. For this I am counting exactly how many rows this page can incorporate and based on that I am inserting empty lines without inside top and bottom border.
The file does not have any header/ footer or any other details as of now.
While I am creating the file I am shown the file which is coming in print preview of covering the whole page of size A4.
But this document is printed only on 80% of paper. I am having 0.3 cm margins but in print the whole page is not printed.
This does not seem to be the printer issue because if other software like Google Chrome are used then it prints the complete page.
So I want to ask that how can I solve this? I tried to search about this but till now I couldn't solve it. I think of this as an issue that whenever I am using XWPFDocument, its margins and all are changed set to default size. I don't know whether this is the issue or something other is, do I need to write some commands to preserve the margins and all or there's something that I need to do.
How can I solve this thing?
Thank you.

iReport : List Standard Size Issue

I have a strange problem with Jasper Reports`iReport:
I have to use Version 3.7.6 and in this version I have to create a dynamic table.
The user is able to define how many columns the table will have and I am calculating this table in the Java - Backend before report initialization and present it to the user. I am not using the table component for this but instead a List of Textfields:
The Java Representation looks like this (very simple):
List<List<String>>
What I am doing is to take a list component that is using subreports to print the contents of the many strings into the report. The List component is printing columns of text fields next to each other (Print Order Horizontal). The subreport consists of nothing but a textfield. This textfield is printed over and over for every column and in the end I have a nice table.
This works very well.
What doesn´t work is when I try to make the text field in the subreport wider.
When it has the standard size of 53px the table looks very well.
When I increase the size I notice that the textfield itself gets wider but the list component still thinks the next column should be 53px. So the text fields overlap each other because the list component refuses to increase its size.
Is there any way to tell the list component to increase its column size when printing horizontal ?
Ok, here is the answer:
The size of the columns for the list component is derived from the columnWidth property of the report. When I change this I can create wider textfields ...

How to create two column and with auto number in jasper report to excel?

Hello i have a problem to create report that need to display as two column, but my output is like this
the focus is the auto numbering value, anyone could help me??
It's hard to say without reviewing some code but it looks like your code is entering your entires by alternating columns. You should fill the first column with entries before moving onto the second column (to achieve your desired numbering).

Droplist in Excel using Poi

How can I create a drop list in excel like drop list in html with the inbuilt "value" like attribute?
My Requirement is: I want to show the description which is not stored in database, but the code for description.
Ex: I have a subject list in an excel cell, for Science the description is "Science", but I want to store the code "SCI" in the Database.
You could use an ActiveX ComboBox in a worksheet, available from the Developers tab.
Enter both columns of data into the worksheet - you can hide the columns. Then set properties of the combobox:
ColumnCount 2
BoundColumn 1
ColumnWidths 0 pt; 20 pt
Set the ListFillRange and LinkedCell.
I understand there used to be issues with distributing workbooks containing ActiveX controls. I am not sure if this is still an issue, particularly when used a common (standard) control.
Of course, Excel is not designed to be a front-end to a database, so you'll need to write all the code to keep everything in-sync.
You could use the simpler Form Control/ComboBox. This will only store the index number in a cell - it does not have any events that you can use. You could use a formula based on the linked cell, that stores the description in another cell. When the user (presumably) clicks a button to submit the data, you would retrieve and store the description from this cell.
Hmm I can see many placeholder occurs all around the web related to java poi... but it seems there is no solution for your question. The only way I found to manage this is to set the cell value with my default text - the first value!

Categories