我正在使用“打开文件”对话框打开文件,我想确认该文件为Excel格式。
我打开的文件是“ C:\ Desktop \ Distribution.xls”,但是我的if语句的两个条件都评估为true。我应该使用另一种方法吗?
DialogResult result = openFileDialog1.ShowDialog();
if (result==DialogResult.OK)
{
file = openFileDialog1.FileName;
file = file.Trim();
if (!file.EndsWith(".xlsx")||!file.EndsWith(".xls"))
{
MessageBox.Show("Incorrect file format. Please save file in an .xls format");
}
else
{
book = application.Workbooks.Open(file);
sheet = (Worksheet)book.Worksheets[1];
range = sheet.get_Range("A1", "A1".ToString());
range.EntireRow.Delete(XlDirection.xlUp);
sheet.Cells[1, 2].EntireColumn.NumberFormat = "@";
book.SaveAs(csvConverstion, XlFileFormat.xlCSV);
book.Close(false, Type.Missing, Type.Missing);
application.Quit();
}
茅侃侃
相关分类