我使用了 openfiledialog 并对其进行过滤以获取:.xls 和 .xlsx 和 .xlsm 文件。但我不知道接下来要做什么,我用 firstName 和 lastName 构建了一个工人类,我想从 excel 文件中获取数据并将其放入变量中。
这是我的 openfiledialog 代码:
private void ExcelLoad_Click(object sender, EventArgs e)
{
int size = -1;
openFileDialog1.Title = "Browse Excel file";
openFileDialog1.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file size in debugging …Run Code Online (Sandbox Code Playgroud) 我正在解析这样的日期: "Sat, 30 Jan 2016 00:03:00 +0300"
但在某些日期它给我这个例外:
Caused by: java.time.DateTimeException: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30
Run Code Online (Sandbox Code Playgroud)
或这个:
java.time.format.DateTimeParseException: Text 'Tue, 30 Jan 2016 00:06:00 +0300' could not be parsed: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30
Run Code Online (Sandbox Code Playgroud)
这是我的一些代码:
DateTimeFormatter newformatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
OffsetDateTime odt = OffsetDateTime.parse( date , newformatter );
Instant instant = odt.toInstant();
java.sql.Timestamp ts = java.sql.Timestamp.from( instant );
Run Code Online (Sandbox Code Playgroud)
输入例如抛出异常:
Input:"Tue, …Run Code Online (Sandbox Code Playgroud)