Hello
so there is excel form for my job which must be filled when something sells.
In it are 19 rows for products.
I coded am app which is filling this form. Everything going good but my problem is if all rows where filled on first sale and second sales products quantity is example 5 it fills first 5 and another 14 rows is not be empty it is be full with first sales products. Below I will post my code
its already 3 day im trying to solve this problem.
I have code which must clear rows but its working only two rows
this is code : rangeProductNames.EntireRow.ClearContents();
Is There anything which can convert xls file with c# code (which will be create new excel file like this form)?
Can I do so that when code fills file it does not save but only prints it?
I need advices or good tutorials how to create new file
Sorry for my English.
Please Help me. It's very very important for me.
private void btnExportInExcel_Click(object sender, EventArgs e)
{
nudZednadebNumber.Value++;
string address = txtFileAddress.Text;
OpenExcelWorkbook(address);
_sheet = (Excel.Worksheet)_sheets[1];
_sheet.Select(Type.Missing);
Excel.Range rangeProductNames = (Excel.Range)_sheet.get_Range(_sheet.Cells[27, "B"] as Excel.Range, _sheet.Cells[27 + dgvProducts.Rows.Count - 1, "B"] as Excel.Range);
Excel.Range rangeProductQuantity = (Excel.Range)_sheet.get_Range(_sheet.Cells[27, "M"] as Excel.Range, _sheet.Cells[27 + dgvProducts.Rows.Count - 1, "M"] as Excel.Range);
Excel.Range rangeProductPrice = (Excel.Range)_sheet.get_Range(_sheet.Cells[27, "O"] as Excel.Range, _sheet.Cells[27 + dgvProducts.Rows.Count - 1, "O"] as Excel.Range);
Excel.Range rangeOneType = (Excel.Range)_sheet.get_Range(_sheet.Cells[27, "K"] as Excel.Range, _sheet.Cells[27 + dgvProducts.Rows.Count - 1, "K"] as Excel.Range);
string[,] proNames = new string[dgvProducts.Rows.Count, 1];
string[,] proQuantity = new string[dgvProducts.Rows.Count, 1];
string[,] proPrice = new string[dgvProducts.Rows.Count, 1];
string[,] proOneType = new string[dgvProducts.Rows.Count, 1];
rangeProductNames.EntireRow.ClearContents();
for (int i = 0; i < dgvProducts.Rows.Count; i++)
{
proNames[i, 0] = dgvProducts.Rows[i].Cells["cProductName"].Value.ToString();
proOneType[i, 0] = dgvProducts.Rows[i].Cells["cOneType"].Value.ToString();
proQuantity[i, 0] = dgvProducts.Rows[i].Cells["cQuantity"].Value.ToString();
proPrice[i, 0] = dgvProducts.Rows[i].Cells["cCommonPrice"].Value.ToString();
}
rangeProductNames.set_Value(Type.Missing, proNames);
rangeOneType.set_Value(Type.Missing, proOneType);
rangeProductQuantity.set_Value(Type.Missing, proQuantity);
rangeProductPrice.set_Value(Type.Missing, proPrice);