问题
So I have this code, but i want to know how possible it is to convert from a result gotten from an SQL DataTable to print on a Microsoft word content control My code looks 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;
}
I have sought the internet and I have not gotten anything that looks like a lead. Please I do need clarifications on this issue pls.
来源:https://stackoverflow.com/questions/59826966/how-i-can-export-from-a-datatable-to-a-content-control-in-c-sharp-using-openxml