locked
How can I use List<SdtBlock> in OpenXml to print a Table RRS feed

  • Question

  • User-849204934 posted

    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.

    Monday, January 20, 2020 1:52 PM

All replies