需要咨询.我正在尝试这样做,但没有任何结果 [英] Need Advices. Im trying to do that but nothing comes out
问题描述
你好
所以我有一份出色的工作表格,当有东西卖出时必须填写.
其中有19行产品.
我编写了填写此表格的应用程序代码.一切进展顺利,但我的问题是,如果在第一笔销售和第二笔销售产品数量上填充的所有行都是示例5,则它填充前5行,而另外14行不是空的,则它充满了第一笔销售产品.下面我将发布我的代码
已经有3天的即时消息试图解决此问题.
我有必须清除行的代码,但它只能工作两行
这是代码:rangeProductNames.EntireRow.ClearContents();
有什么可以用c#代码转换xls文件的文件(将以这种形式创建新的Excel文件)吗?
我可以这样做,以便在代码填充文件时不保存而是仅打印文件吗?
我需要如何创建新文件的建议或良好的教程
对不起,我的英语.
请帮我.对我来说非常重要.
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);
推荐答案
这是一个很大的补充,我认为您可能已经在使用:
http://exceldatareader.codeplex.com/
使用它可能会更容易从文件创建数据集,按需要对其进行操作,然后将数据集写回带有随机生成的文件名的新" excel文件(GUID适用于我),然后运行它. ..获取数据集的示例:
This is a great add on that I think you may already be using:
http://exceldatareader.codeplex.com/
Using that it would probably be easier to create a dataset from the file, manipulate it as you would like then write the dataset back to a "new" excel file, with a randomly generated filename (GUID works for me) and then run it... Example to get the dataset:
DataSet output = new DataSet();
using (FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
{
Excel.IExcelDataReader excelReader = fileName.IndexOf(".xlsx") > -1 ? Excel.ExcelReaderFactory.CreateOpenXmlReader(stream) :
Excel.ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
output = excelReader.AsDataSet(false);
}
这篇关于需要咨询.我正在尝试这样做,但没有任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!