Clear Previous selection of Dropdown in EXCEL usingApache POI - apache

I have developed the excel using the Apache NPOI dll using HSSFWORKBOOK. But in my excel having 3 dependent dropdowns one in each other.
Here my question is I am unable to clear the cell value of dependent dropdowns. Let say like dropdown1 have country values and on the selection of this dropdown2 state values got a filter and selected one of the state. Now if I changed the country again able to filter the data but whatever the previous state selection not getting cleared.
code ref:
No, i am just referring the list of columns data from sheet2 to sheet1 using the formulae. below is code ref:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//if (i >= MaxRowCount)
//{
// sheet2.CreateRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
// MaxRowCount += 1;
//}
//else
// sheet2.GetRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
if (CategoryCount == 250)
{
rownumber = rownumber + 3000;
CategoryCount = 16;
MaxRowCount = 0;
}
DataRow[] DR = ds.Tables[1].Select("LOCATION_ID=" + ds.Tables[0].Rows[i][0].ToString());
int RowCount = 0;
//int rownumber = 1000;
foreach (DataRow d in DR)
{
if (RowCount >= MaxRowCount)
{
sheet2.CreateRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
MaxRowCount += 1;
}
else
{
sheet2.GetRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
}
RowCount++;
}
IName DeptHierarchy_Dept = hssfworkbook.CreateName();
DeptHierarchy_Dept.NameName = "XDeptHierarchy_Dept_SUB" + (XDeptHierarchy_Dept_SUBCount).ToString();
if (CategoryCount / 26 < 1)
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + CategoryCount)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + CategoryCount)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
else
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
CategoryCount++;
XDeptHierarchy_Dept_SUBCount++;

You are looking for "Dependent Drop Down Lists". You'll have to be creative for your formula because your row will keep changing.
one approach i can think of is store the list of "Country-capital" on named region some where deep in excel. On selection of country, parse and find the capital from named region and populate your target cell.
Please see the documentation.
Also this link;

Related

How to store the first N rows of the current record as an array vector?

I defined a table as follows:
syms = "A"
datetimes = 2021.01.01..2022.01.01
n = 200
t = table(take(datetimes,n) as trade_time, take(syms,n) as sym,take(500+rand(10.0,n), n) as price)
You can try the following script:
syms = "A"
datetimes = 2021.01.01..2022.01.01
n = 200
t = table(take(datetimes,n) as trade_time, take(syms,n) as sym,take(500+rand(10.0,n), n) as price)
dayNum = 3
tbName = "t"
def getLastNDay(tbName, dayNum){
colName = "price"
scripts = "update " + tbName + " set lastNPrice = fixedLengthArrayVector("
for(n in 1..(dayNum-1)){
scripts = scripts + "move(" + colName + "," + n + "),"
}
scripts = scripts +"move(" + colName + "," + dayNum + "))"
print(scripts)
runScript(scripts)
}
getLastNDay(tbName, dayNum)
Output:

inserting list data into table in itext7 pdf (xamarin android)

I have a list and I need to put the data of this list in a pdf file. I searched and found the itext7 library where you can create a table in the pdf. I wrote the following code:
var path2 = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
filePath = Path.Combine(path2.ToString(), "Client's_Account.pdf");
stream = new FileStream(filePath, FileMode.Create);
PdfWriter writer = new PdfWriter(stream);
PdfDocument pdf2 = new iText.Kernel.Pdf.PdfDocument(writer);
Document document = new Document(pdf2,iText.Kernel.Geom.PageSize.TABLOID);
Paragraph header;
acc_info acc = new acc_info();
//foreach (var t in tableItems)
//{
// string txt = t.itembarcode + " " + t.itemsunitcode + " " + t.name + "\n";
// header = new Paragraph(txt);
// document.Add(header);
//}
iText.Layout.Element.Table table = new iText.Layout.Element.Table(5, false);
// table.SetWidth(400).SetFixedLayout();
table.AddCell(new Cell(1, 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph("Date")));
table.AddCell(new Cell(1, 2).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph("Reference")));
table.AddCell(new Cell(1, 3).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph("Description")));
table.AddCell(new Cell(1, 4).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph("Debit")));
table.AddCell(new Cell(1, 5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph("Credit")));
for (int i = 0; i < user.tableItems_accInfo.Count; i++)
{
int j = 0;
table.AddCell(new Cell(i + 2, j + 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph(user.tableItems_accInfo[i].jvdate)));
j = j + 1;
table.AddCell(new Cell(i + 2, j + 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph(user.tableItems_accInfo[i].jvref)));
j = j + 1;
table.AddCell(new Cell(i + 2, j + 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph(user.tableItems_accInfo[i].desc)));
j = j + 1;
table.AddCell(new Cell(i + 2, j + 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph(user.tableItems_accInfo[i].jvdebit)));
j = j + 1;
table.AddCell(new Cell(i + 2, j + 1).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).Add(new Paragraph(user.tableItems_accInfo[i].jvcredit)));
}
document.Add(table);
string txt = "\n \n Total Credit= " + tot_crdt.Text +"\n \n Total Debit= "+tot_dbt.Text+ "\n \n Total Balance= "+balance.Text;
header = new Paragraph(txt);
document.Add(header);
document.Close();
Toast.MakeText(this.Context, "PDF Generated", ToastLength.Short).Show();
but the table I get is so bad even if I change the pdf pagesize (A4, legal, tabloid...). what did I do wrong?
here's the table that I get:
thanks in advance
You seem to misinterpret the Cell constructor parameters. They don't represent the row and column in which the cell shall go but instead the number of rows and columns the cell shall span.
Instead of
new Cell(n, m)
for various n and m, therefore, you should use
new Cell()

SQL: Automatic numbering

I've got a question about SQL language which I couldn't find an answer for. I want SQL to automatically insert a number based off how much rows there are. Using an ASP.NET website I'm adding new rows and deleting rows. This means when I delete rows I want the table to automatically respond to that.
It is pretty hard to explain for me, so I already did some thinking ofcourse. I can fill it in using a C# code but when a row is deleted it ofcourse does not automatically change.
if (kisten < 4)
{
staple = 1;
}
else
{
if (staple1 >= 4)
{
staple = stapel2 + 1;
}
else
{
stapel = stapel2;
}
}
So what this means is that one staple contains 4 blocks. But I want if one row gets removed from the staple the first row of the second staple gets added to the first staple, so it gets value '1'.
Hope I am clear enough. If not, please don't hesitate to ask.
EDIT:
I am using SQL Server indeed. Here is a clear example of what I mean:
This is when everything is inserted using C# and as u can see it works fine.
This is when rows get deleted. As you can see the column 'Stapel' does not automatically change the number
What I want when rows get deleted
So after hours of trying I found a solution which works perfectly. Like so:
SqlCommand cmd11 = new SqlCommand("select count(kistid) from [dbo].[kist] where rij = '" + rij + "'", con);
int countrij = (Int32)cmd11.ExecuteScalar();
int procent = (4 / countrij * 100);
int hoeveel;
int hoeveel2 = (countrij % 4);
int hoeveel1;
if (hoeveel2 == 0)
{
hoeveel = (countrij / 4);
hoeveel1 = hoeveel;
for (int i = 0; i < hoeveel; i++)
{
SqlCommand sqlquery5 = new SqlCommand("UPDATE TOP (" + countrij + ") Kist SET Stapel ='" + hoeveel1 + "' WHERE Rij ='" + rij + "'");
sqlquery5.CommandType = System.Data.CommandType.Text;
sqlquery5.Connection = con;
sqlquery5.ExecuteNonQuery();
hoeveel1 = hoeveel1 - 1;
countrij = countrij - 4;
}
}
else
{
hoeveel = ((countrij - hoeveel2) / 4) + 1;
hoeveel1 = hoeveel;
for (int i = 0; i < hoeveel; i++)
{
SqlCommand sqlquery5 = new SqlCommand("UPDATE TOP (" + countrij + ") Kist SET Stapel ='" + hoeveel1 + "' WHERE Rij ='" + rij + "'");
sqlquery5.CommandType = System.Data.CommandType.Text;
sqlquery5.Connection = con;
sqlquery5.ExecuteNonQuery();
hoeveel1 = hoeveel1 - 1;
countrij = countrij - hoeveel2;
hoeveel2 = 4;
}
}
To automatically do something in a database when UPDATE, DELETE or INSERT command is executed for a given table you have to use CREATE TRIGGER to define a new trigger.
For more information just read about usage of triggers in your specific database server. For example for SQL Server you can read this.

Fingerprint Hardware ID GetHexString

I found a fingerprint class in C# here
I'm trying to convert the function below to VB .NET but I am having issues with the line that reads s+ = (char)....Any help would be appreciated.
private static string GetHexString(byte[] bt)
{
string s = string.Empty;
for (int i = 0; i < bt.Length; i++)
{
byte b = bt[i];
int n, n1, n2;
n = (int)b;
n1 = n & 15;
n2 = (n >> 4) & 15;
if (n2 > 9)
s += ((char)(n2 - 10 + (int)'A')).ToString();
else
s += n2.ToString();
if (n1 > 9)
s += ((char)(n1 - 10 + (int)'A')).ToString();
else
s += n1.ToString();
if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
}
return s;
}
Is there a better way to write this function in VB.NET?
This
s += ((char)(n1 - 10 + (int)'A')).ToString();
is the same as
s &= Chr((n1 - 10 + Asc("A")))

Datatable Select all rows

I want to insert into table for specific columns into table using select * from datatable.But it is giving me an array .. is there any way I can get the Insert work.
all I want to do is
Insert into table1 (id,name,status) select * from datatable
query += "Insert into " + tableName.ToLower() + "";
query += "(";
for (int i = 0; i < dt.Columns.Count; i++)
{
if (i != dt.Columns.Count - 1)
query += dt.Columns[i].ColumnName.ToLower() + ",";
else
query += dt.Columns[i].ColumnName.ToLower();
}
query += ")";
DataRow[] result = dt.Select();
query += "select * from " + result
You Can't use two sql Statements at once like that you have to separate them in two different objects or variables (It's sometimes allowed when you end each by a semicolon ; but not in your case )
try to get each cell value in the row
query += "Insert into " + tableName.ToLower() + "";
query += "(";
for (int i = 0; i < dt.Columns.Count; i++)
{
if (i != dt.Columns.Count - 1)
query += dt.Columns[i].ColumnName.ToLower() + ",";
else
query += dt.Columns[i].ColumnName.ToLower();
}
query += ")";
query += "values ( ";
string temQry=query;//you need it more than once
DataRow[] result = dt.Select();
for (int i = 0; i < dt.Rows.Count; i++){
for (int j = 0; j < dt.Columns.Count; j++){
if ((j+1)<dt.Columns.Count){
query += result[i].item(j) +"," ;
}
else {
query += result[i].item(j);}
}
query=temQry; //recover the query for each new row
}