In my previous articles related to EPPlus I have shown you that how you can generate Basic and Advance reports using EPPlus. Many people has asked me that how we can read the contents of an excel file using EPPlus. This is actually quite simple task. Here is the code to do this:-
Things are very simple so I am not sharing more details. You can use above code to edit your existing excel files as well.
To download code, use this link.
Feel free to comment. Happy Coding !!!
using (ExcelPackage p = new ExcelPackage()) { using (FileStream stream = new FileStream("92b69c48-dda7-4544-bdcc-c6925a5f1bec.xlsx", FileMode.Open)) { p.Load(stream); ExcelWorksheet ws = p.Workbook.Worksheets["Sample Sheet"]; int rowIndex = 2; string text = ws.Cells[rowIndex, 1].Value.ToString(); //Read Text MessageBox.Show("Text in [" + rowIndex + ",1]=" + text); string comment = ws.Comments[0].Text; // Access Comments MessageBox.Show("Comments = " + comment); string pictureName = ws.Drawings[0].Name;// Access Picture MessageBox.Show("Picture = " + pictureName); } }
Things are very simple so I am not sharing more details. You can use above code to edit your existing excel files as well.
To download code, use this link.
Feel free to comment. Happy Coding !!!
freeboot · 670 weeks ago
Vaibhav · 553 weeks ago
Thanks for the code. I can execute them perfectly.
Can u tell me how I should edit the file
I have tried adding
worksheet.Cells[6, 1].Value = "12010";
But I don't get any change in the value
Zeeshan Umar · 548 weeks ago
{
using (FileStream stream = new FileStream("92b69c48-dda7-4544-bdcc-c6925a5f1bec.xlsx", FileMode.Open))
{
p.Load(stream);
ExcelWorksheet ws = p.Workbook.Worksheets["Sample Sheet"];
int rowIndex = 2;
string text = ws.Cells[rowIndex, 1].Value.ToString(); //Read Text
MessageBox.Show("Text in [" + rowIndex + ",1]=" + text);
string comment = ws.Comments[0].Text; // Access Comments
MessageBox.Show("Comments = " + comment);
string pictureName = ws.Drawings[0].Name;// Access Picture
MessageBox.Show("Picture = " + pictureName);
}
//Here is the change
p.Save();
}
Vaibhav · 553 weeks ago
I had to add
p.Save();
at the end of the function and I could add any entry I wanted.
Thanks for the codes!
Zeeshan Umar · 548 weeks ago
shanshah007 1p · 550 weeks ago
Zeeshan Umar · 548 weeks ago
Sulhadin Öney · 509 weeks ago
dsfds · 485 weeks ago
Dave · 454 weeks ago
Douglas Peng · 434 weeks ago
Zeeshan Umar · 433 weeks ago
lucky · 373 weeks ago
My Telenor APK · 349 weeks ago