Populate existing excel template containing columns from a table in SQL Server using C# -


my c# project requires excel report generation. have existing excel template contains columns values populated sql server table , fields(e.g testcasepassed, testcasefailed etc.)in excel template populated values code.

i.e. excel template format

testcasepassed: testcasefailed:

date:

name designation salary teststatus

i require c# code process. in advance.

i new c# , don't have idea how proceed yes have using microsoft.interop.

there has 100s of way of doing and, without being more specific, question may more opinion based anythign else.

if had task (and assuming there reasonably small number of records) existing db i'd

  1. entity framework db first existing sql database
  2. get entries db
  3. write spreadsheet using epplus

i therefore might end code this:

list<entry> fromdb() {     list<entry> res;     using (var dbcontext = new myentities()     {         res = dbcontext.where(e=>meetsmyfiltercriteria(e)).tolist()     }     return res; }  main() {     fileinfo fileinfo = new fileinfo("path/to/exceltemplatefile.xlsx");      using (var excelpackage = new excelpackage(fileinfo))     {         excelworksheet sheet = excelpackage.workbook.worksheets["myworksheenname"];         baserange startrange = sheet.range["a2"] //or wherever data go         int offset=0;         foreach (entry in fromdb())         {             startrange.offset(offset,0).value = entry.propertya;             startrange.offset(offset,1).value = entry.propertyb;             startrange.offset(offset,2).value = entry.propertyc;              // , on ...              offset++;         }          excelpackage.saveas("path/to/exceloutput.xls");      } } 

this approach nice , easy implement not scale nicely 1000s of exports of hundreds of thousands of rows provided talking small numbers of rows , relativaly few export poor performance negligible , offset ease of implementation.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -