Skip to content

DISPLAY SQL TABLE ROWS TO WORD OR PDF LIKE BELOW FORMATE

JAYRAM

Asked Mar 2, 2014, 12:59 AM EST1 answer
Share
LinkedInX
i have sql table like this below

Sno  Elector's Name                  Father'sName     House No       Age  Sex        Id
1   RAGHAVENDHAR                 LAXMANACHARI  1-1-*400/401 36   Male     ZTS1298603
2   BHARATHA LAKSHMIARIGILA SAIKUMAR A      1-1-1            41   Female  ZTS1083807
3   HMA BINDU SENAGASETI       KRISHNA RAO S 1-1-1           37   Female  ZTS1083815
4
5
6
7
.........i have more then 2000 rows .....

i would like display  sql table date to MS word or pdf  like below formate
plz help me...........


.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi JAYRAM here is what you are looking for.
    You first need to define a template file with the required layout and placeholders (in which you want to import the data later on).
    Actually you don't have to create a template file, but creating a Word document from scratch in C# with the required layout and placeholders is a bit of an unnecessary hassle.
    So for example here is a template file:

    The template has the desired layout of the single record and has placeholders which names correspond to the DataTable's columns name. Also the area is wrapped around the range definition ("TableData").

    Now you need to read the template Word document with C#:
    Code
    // Load template file.
    DocumentModel document = DocumentModel.Load("Template.docx");
    After that you can execute the mail merge process on your Word file with C#:
    JavaScript
    // Set mail merge prefixes, I used different prefixes for defining range from the default ones.
    document.MailMerge.RangeStartPrefix = "S:";
    document.MailMerge.RangeEndPrefix = "E:";
     
    // Execute importing of DataTable's data in "TableData" named range.
    document.MailMerge.Execute(sourceTable, "TableData");
    And save the result into a file:
    Code
    document.Save("Output.docx");

    Note that you can create a PDF file in same C# manner, you just need to replace the output file's extension from ".docx" to ".pdf". 
    0