Lỗi "exception from hresult 0x800a03ec"
private void import1_Click(object sender, EventArgs e)
{
// Create Object
OpenFileDialog fopen = new OpenFileDialog();
// Show ass
fopen.Filter = "Excel(.xlsx)|*.xlsx";
fopen.FilterIndex = 1;
fopen.RestoreDirectory = true;
fopen.Multiselect = false;
fopen.Title = "Import File";
fopen.ShowDialog();
//xu ly
if (fopen.FileName != "")
{
lblPath.Text = fopen.FileName;
// Create Object
Excel.Application app = new Excel.Application();
//Open Excel
Excel.Workbook wb = app.Workbooks.Open(fopen.FileName);
try
{
// mo sheet
Excel._Worksheet sheet = wb.Sheets[1];
Excel.Range range = sheet.UsedRange;
// doc du lieu
int rows = range.Rows.Count;
int cols = range.Columns.Count;
for (int c = 1; c <= cols; c++)
{
string columnname = range.Cells[1, c].value.ToString();
ColumnHeader col = new ColumnHeader();
col.Text = columnname;
col.Width = 120;
listProfile.Columns.Add(col);
}
for (int i = 2; i <= rows; i++)
{
ListViewItem item = new ListViewItem();
for (int j = 0; j <= cols; j++)
{
item.SubItems.Add(range.Cells[i, j].Value.ToString());
listProfile.Items.Add(item);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Thong Bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
Để sử dụng tính năng này, Bạn cần đăng nhập bằng tài khoản Howkteam.
Đăng nhập
Để xem được nội dung và giúp Kteam duy trì hoạt động.
Bạn vui lòng tắt Adblock trên website howkteam.vn nhé!
Dùng EPPlus ấy baby. dễ sài
Hình như toidicodedao có 1 bài. Thank đại ca