Beispiel #1
0
        protected void FillBookmarkWithCMAttachmentABNormal(Application app, SqlConnection con, string bookmarkName, string tableName, long cmId, string columnName, string columnCMId)
        {
            this.Logger.Info(tableName);

            object Normal = "Normal";

            string query = "SELECT";

            query = query + " " + columnName;
            query = query + " FROM " + tableName;
            query = query + " WHERE " + columnCMId + " = @CMId";

            using (SqlCommand cmd = con.CreateCommand())
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;
                cmd.Parameters.Add(this.NewSqlParameter("CMId", SqlDbType.BigInt, cmId));

                Range rangeBookmark = app.ActiveDocument.Bookmarks[bookmarkName].Range;
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        string fileContent = dr.GetNullableString(0);
                        if (fileContent != null)
                        {
                            string htmlResult = ConvertHtmlAndFile.SaveToFile(fileContent);

                            try
                            {
                                Application app2           = new Application();
                                Document    sourceDocument = app2.Documents.Open(htmlResult);
                                sourceDocument.Activate();
                                object start = sourceDocument.Content.Start;
                                object end   = sourceDocument.Content.End;
                                Microsoft.Office.Interop.Word.Range myRange = sourceDocument.Range(ref start, ref end);
                                myRange.Select();

                                myRange.Font.Name = "Roboto Light";
                                myRange.Font.Size = 10;

                                IIFCommon.FindEmptyParagraphsAndDelete(sourceDocument);
                                //DeleteCurrentSelectionLine(app2);
                                //myRange.set_Style(ref Normal);
                                sourceDocument.Save();
                                sourceDocument.Close(WdSaveOptions.wdSaveChanges);
                                app2.Quit();

                                rangeBookmark.InsertFile(htmlResult);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                            finally
                            {
                                File.Delete(htmlResult);
                            }
                        }
                    }
                }
            }
        }