SmartXLSX を使用して Excel ファイルを正常に読み取っていますが、問題に直面しています。私のプログラムは、スプレッドシートの他のすべての行とともに、列ヘッダーを新しい行として読み取っています。列ヘッダーをスキップして他の行を読み取るようにプログラムを更新するにはどうすればよいですか。
private void GetCompanies()
{
int count = 0;
Companies = new List<Company>();
string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directory, "Toll-Companies.xlsx");
SmartXLS.WorkBook WB = new WorkBook();
WB.readXLSX(path);
DataTable dt = WB.ExportDataTable();
string CurrentType = string.Empty;
string CurrentCategory = string.Empty;
string Removerow = string.Empty;
string b,c;
//DataRow rowe = dt.Rows[0];
//dt.Rows.Remove(rowe);
//loop through each row
foreach (DataRow dr in dt.Rows)
{
//Get company name in column c from Excel
c = dr[2].ToString();
//Get value in column B from Excel
b = dr[0].ToString();
if (b.StartsWith("Type:"))
{
CurrentType = b.Substring(6).Trim();
}
if (b.StartsWith("Primary Specialty"))
{
CurrentCategory = b.Substring(20).Trim();
}
//if company name is empy then skip row
if (string.IsNullOrEmpty(c)) continue;
//string Type = dr[7].ToString();
//dt.Columns.Add(Type)
//string cmp_type = dr[0].ToString();
//if (string.IsNullOrEmpty(cmp_type) || cmp_type == "Type") continue;
var cmp = new Company();
cmp.company_type = CurrentType;
cmp.company_category = CurrentCategory;
cmp.name = dr[2].ToString();
Companies.Add(cmp);
count++;
}
これにより、求める結果が得られます。SmartXLSX ライブラリでメソッドを探しているかどうかはわかりません。
foreach (DataRow dr in dt.Rows)
{
if(count==0) continue;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加