List<SdtBlock> c# Openxml how to print Table on content control

  • Thread starter Thread starter oderis
  • Start date Start date
O

oderis

Guest
I am trying to print a table to a Content control from a Database (MSSQL), the webservice is supposed to fetch some records and put it to a content control in the form of a table using List.


So I do something like this


public bool PrintTableonContentControl(string connectionString, string DbQuery,string filePath, string placeholderText)
{
try{

DataTable dt = new DataTable();
using(SqlConnection con = new SqlConnection(connectionString)){
con.Open();

using(SqlCommand cmd = new SqlCommand(DbQuery,con)){
using(SqlDataAdapter da = new SqlDataAdapter(cmd)){
da.Fill(dt);

using(WordprocessingDocument theDoc = WordprocessingDocument.Open(filePath, true)){
MainDocumentPart mainPart = theDoc.MainDocumentPart;
List<SdtBlock> sdtSubTable = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val.Value.Contains(placeholderText)).ToList();

// Here it should print the Table on the content control and save

}
}
}
}

}
catch(Exception ex)
{
throw ex;
}
return true;
}



Normally, I know how to use the simple Text and have the text displayed on a Content control, but tables? I have not seen any useful documentation on that, Please I would be needing help in this case.

Continue reading...
 
Back
Top