I have this code to generate a table from mysqlite with itext, but the number of cells is static(only 2) no matter the records I have in the database, can you please help me get dynamic cells depending on the number of records ?Thank you very much
// Table
PdfPTable table = new PdfPTable(2);
// Header
PdfPCell cell1 = new PdfPCell(new Phrase("groups"));
PdfPCell cell2 = new PdfPCell(new Phrase("machines"));
table.addCell(cell1);
table.addCell(cell2);
// Data
db = new Database(FirstActivity.this);
Cursor c = db.getGroupsNamesMachines();
if (c.moveToFirst()) {
do {
String group = c.getString(c.getColumnIndex("groupname"));
cell1 = new PdfPCell(new Phrase(group));
table.addCell(cell1);
String machine = c.getString(c.getColumnIndex("machinename"));
cell2 = new PdfPCell(new Phrase(machine));
table.addCell(cell2);
} while (c.moveToNext());
}
document.add(table);
You are confusing cells with columns, and fields with rows.
The number of fields is known up-front. If you have "SELECT groupname, machinename FROM groupmachines;", you know that each record will have two fields, hence you need 2 columns. If you have "SELECT groupid, groupname, machinename FROM groupmachines;", you will need 3 columns, and so on.
The number of records isn't known up-front. You perform a query, and the Cursor keeps on giving you data as long there are records left. That's not a problem: just add one row to the table for each record. Adding a row happens implicitly in iText: you have a complete row as soon as you've added as many cells as there are columns.
Once you add the table to the document, the rows will be distributed over different pages if the table doesn't fit a single page.
Related
I have a table A with the following columns and data:
Tag_ = P-111
Description_ = Pump
HP_ = 100
RPM_ = 1,800
I have another table B with same columns:
Tag_ = P-111
Description_
HP_
RPM_
Is there a way when I enter data in the Tag_ column in Table B and there is matching data in the same Tag_ column in Table A that I can set up a trigger or automatic command that sends the data from the other columns in Table A to Table B?
I am a new user of MatlabR2021b and I have a table where the last column (with name loadings) spans multiple sub-columns (all sub-columns were added under the same variable/column and are threated as one column). I wanto to create a For loop that goes through each separate loading column and iterates through them, prior to creating a tbl that I will input into a model. The sub-columns contain numbers with rows corresponding to the number of participants.
Previously, I had a similar analogy where the loop was iterating through the names of different regions of interest, whereas now the loop has to iterate through columns that have numbers in them. First, the numbers in the first sub-column, then in the second, and so on.
I am not sure whether I should split the last column with T1 = splitvars(T1, 'loadings') first or whether I am not indexing into the table correctly or performing the right transformations. I would appreciate any help.
roi.ic = T.loadings;
roinames = roi.ic(:,1);
roinames = [num2str(roinames)];
for iroi = 1:numel(roinames)
f_roiname = roinames{iroi};
tbl = T1;
tbl.(roinames) = T1.loadings(:,roiname);
**tbl.(roinames) = T1.loadings_rsfa(:,roiname)
Unable to use a value of type cell as an index.
Error in tabular/dotParenReference (line 120)
b = b(rowIndices,colIndices)**
I executed a stored procedure in java which results into a table of 16 column and 3600 rows.Now I want to access 3 column of the retrieved table in row by row fashion and calculate the average of all column in row wise fashion.To do this,I need to access values of columns one by one .How to do it. My code for accessing column is
while (rs.next())
{
a1=rs.getDouble(7);
a2=rs.getDouble(8);
a3=rs.getDouble(10);
sum +=(a1+a2+a3);
}
return sum/3;
but through this,i think i'am getting a total average of all the columns .But i need average of column row by row i.e average of all three column of first row,then second row ...like this.
You are indeed adding all the values from 3 columns and doing row by row addition.
If you want row by row, then for each entry that you get from database you need to store the result in a list like below and return it where needed:
List<Double> averageList = new ArrayList<Double>();
while (rs.next())
{
a1=rs.getDouble(7);
a2=rs.getDouble(8);
a3=rs.getDouble(10);
averageList.add((a1+a2+a3)/3.0);
}
return averageList;
I have a Crystal report with a table as a datasource and I want to include another table with details for the report footer.
I have two data sources in the report which are not linked, but when the selection criteria returns no rows from the main table, the results from the non-empty non-linked source are also empty.
I suspect it's doing a cross join between the two datasources, so if one is empty, that joined with another is also empty. The problem is I need my rows from the non-empty table to show in the report footer section, and they're getting suppressed by the other, empty datasource.
How can I get rows from an independent table to show in the report footer when the selection criteria and their parameter choices return an empty result set in the main table?
Thanks for your help,
-Beth
Also, I tried using a command as a datasource with sql like this:
select * from waitlist
union all
select distinct null as reportID, null as ..., lastupdated
from waitlist
but it still returns null for lastupdated and suppresses the subreport in the report footer.
I ended up setting my report datasource to a view which unioned another row to the table. I also needed to change my selection criteria so it allows this row to pass through.
Here's my datasource:
CREATE VIEW [dbo].[vw_rpt_waitlist] AS
select * from waitlist
union all
select distinct
reportID,
null as (fields...),
lastupdated,
'reserved' as countyName
from
waitlist
and here's my record selection formula:
({vw_rpt_waitlist.countyName} = {?County} or
{vw_rpt_waitlist.countyName} = "reserved") and
{vw_rpt_waitlist.reportID} = 14
I'm also suppressing the detail section if there were real rows returned:
formula = {vw_rpt_waitlist.countyName} = "reserved"
and to get the parameterized county name they selected in the page header of the report, I'm using:
dim t as string
dim c as string
if {vw_rpt_waitlist.countyName}="reserved" then
c = {?County}(1)
else
c = {vw_rpt_waitlist.countyName}
end if
t = "Waitlist by " + {#serviceTitle} + " and Waiver Need Index as of "
+ cstr({vw_rpt_waitlist.lastUpdated},"MM/dd/yyyy")
formula = t
Since the 'reserved' county always comes through, the subreports are not suppressed.
I was wanting to delete a column using openxml, I am able to clear the contents of the cell, but have been unable to find documentation to delete the column as to shift the other cells left when the column is deleted. How may I delete the column using openxml where it will shift the cells to the left?
I discovered that OpenXml has no way to delete a column on its own. Therefor to solve my problem I wrote a function that first removed the contents of the cells in the column I was deleting and then to set the cell reference of the columns that came behind the column I was deleting up a column.
You can iterate for each row and remove the cell you need
private void RemoveCell(int rowIndex, int colIndex)
{
SheetData sheetData = _worksheetPart.Worksheet.GetFirstChild<SheetData>(); // get the sheet
Row row = sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex == rowIndex);
if (row != null && row.Count() > colIndex)
row.RemoveChild(row.ElementAt(colIndex));
}