【发布时间】:2021-05-26 23:20:05
【问题描述】:
我是 C# 编程的新手,想知道如何从 Excel 中逐个单元格地读取数据。在下面的代码中,我从 excel 的 A 列中获取一组数据,如 pValue1= a;b;c;d%;e%;f%;现在,如果列 A=ID 的标题,我只想将末尾带有 % 的值推送到不同的数组中。另外,我想用单引号将 pValue1 中的每个项目括起来。
输入:
| ID | Name |
|---|---|
| a | roy |
| b | may |
| c | Jly |
| d% | nav |
| e% | nov |
| f% | lio |
预期输出: pValue1='a';'b';'c' pValue3= d%e%f%
try {
Utils.ExcelFile excelFile = new Utils.ExcelFile(excelFilename);
DataTable excelData = excelFile.GetDataFromExcel();
// Column headers
param1 = 0 < excelData.Columns.Count ? excelData.Columns[0].ColumnName :string.Empty;
param2 = 1 < excelData.Columns.Count ? excelData.Columns[1].ColumnName :string.Empty;
ArrayList pValueArray1 = new ArrayList();
ArrayList pValueArray2 = new ArrayList();
if (pValueArray1.Count > 0) pValue1 = string.Join(";", pValueArray1.ToArray()) + ";";
if (pValueArray2.Count > 0) pValue2 = string.Join(";", pValueArray2.ToArray()) + ";";
}
【问题讨论】: