How I can export from a DataTable to a Content control in C# using Openxml?

流过昼夜 提交于 2020-01-30 11:49:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!