使用EPPlus,我想读取一个excel表,然后将每列的所有内容存储到相应的列中List.我希望它能识别表的标题并根据它对内容进行分类.
例如,如果我的excel表如下:
Id Name Gender
1 John Male
2 Maria Female
3 Daniel Unknown
Run Code Online (Sandbox Code Playgroud)
我希望数据存储在List<ExcelData>哪里
public class ExcelData
{
public string Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用标题名称调出内容.例如,当我这样做时:
foreach (var data in ThatList)
{
Console.WriteLine(data.Id + data.Name + data.Gender);
}
Run Code Online (Sandbox Code Playgroud)
它会给我这个输出:
1JohnMale
2MariaFemale
3DanielUnknown
Run Code Online (Sandbox Code Playgroud)
这真的是我得到的:
var package = new ExcelPackage(new FileInfo(@"C:\ExcelFile.xlsx"));
ExcelWorksheet sheet = package.Workbook.Worksheets[1];
var table = sheet.Tables.First();
table.Columns.Something //I guess …Run Code Online (Sandbox Code Playgroud) const cond = false
const extraInfo = [
{
a: 11,
b: 25
},
{
a: 12,
b: 34
},
{
a: 1,
c: 99
}
]
const userInfo = [
{
z: 8
},
{
z: 10
},
...(cond && extraInfo)
]
Run Code Online (Sandbox Code Playgroud)
什么时候cond是真的,我想要额外的和用户信息.
如果cond为false,则仅需要userInfo.
问题是什么时候cond是假的,我明白了
TypeError :(中间值)(中间值)(中间值)[Symbol.iterator]不是函数
我的理解是,在这种情况下,我不允许使用布尔值作为扩展元素...false.
但...( cond ? extraInfo : {} )似乎也没有用.
到底是怎么回事?
我查看过其他帖子,所有帖子都知道不需要的字符.在我的情况下,我有一堆我想要的角色,我只想保留那些.
我的代码太乱了:
private string RemoveUnwantedChar(string input)
{
string correctString = "";
for (int i = 0; i < input.Length; i++)
{
if (char.IsDigit(input[i]) || input[i] == '.' || input[i] == '-' || input[i] == 'n'
|| input[i] == 'u' || input[i] == 'm' || input[i] == 'k' || input[i] == 'M'
|| input[i] == 'G' || input[i] == 'H' || input[i] == 'z' || input[i] == 'V'
|| input[i] == 's' || input[i] == '%')
correctString += input[i];
}
return …Run Code Online (Sandbox Code Playgroud) 我这里有一个错误代码,因为我无法检查 string 是否等于 string[]。
public void SetCh1Probe(string input)
{
string[] option= {"1:1", "1:10", "1:100"}
//I wanna check if input is equal to any of the string array
if (input != option.Any(x => x == option))
{
MessageBox.Show("Invalid Input");
}
else
{
//Proceed with other stuffs
}
}
Run Code Online (Sandbox Code Playgroud)
我将有大量这样的方法,每种方法都有不同的string[] options. 我真的想要一个简洁的模板,可以用于其余的方法。有人可以帮忙吗?
c# ×3
string ×2
arrays ×1
c#-4.0 ×1
char ×1
css ×1
ecmascript-6 ×1
epplus ×1
epplus-4 ×1
excel ×1
if-statement ×1
javascript ×1
linq ×1