openxml常用标签及笔记

1.常用标签

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
   
  



      
        
        
      




    
        
            
                
            
            
                这是页眉
            
        
    
    
        
            
                
            
            
                这是页脚
            
        
    




    

 

2.痕迹处理

1)书签

 if (bookmark.Name == bookmarkDataVal.Key)
                        {
                            Run bookmarkText = bookmark.NextSibling();
                            if (bookmarkText != null)  // if the bookmark has text replace it
                            {
                                // RunProperties runProperties = new RunProperties(); //属性
                                //Color color = new Color() { Val = "0000FF" };
                                //Underline underline = new Underline();
                                //underline.Val = UnderlineValues.Single;
                                //runProperties.Append(color);
                                //runProperties.Append(underline);
                                //   bookmarkText.RunProperties = runProperties;
                                //  bookmarkText.GetFirstChild().Text = bookmarkDataVal.Value;



                                Text text = new Text(bookmarkDataVal.Value);
                                RunProperties runProperties = new RunProperties(); //属性
                                                                                   //Color color = new Color() { Val = "0000FF" };
                                                                                   //Underline underline = new Underline();
                                                                                   //Font font = new Font();
                                                                                   //  font.h
                                                                                   //   underline.Val = UnderlineValues.Single;
                                                                                   //  runProperties.Append(underline);
                                                                                   //   runProperties.Append(color);
                                                                                   //Run run = new Run(runProperties);
                                                                                   //run.Append(text);

                                //Inserted insert = new Inserted();
                                //insert.Id = Guid.NewGuid().ToString();

                                //insert.Author = new StringValue() { Value = "王大大222" };
                                //insert.Date = DateTime.Now;
                                //insert.AppendChild(text);

                                bookmarkText.GetFirstChild().Text = "";
                                InsertedRun insert = new InsertedRun(runProperties);
                                insert.Id = Guid.NewGuid().ToString();

                                insert.Author = new StringValue() { Value = "王大大222" };
                                insert.Date = DateTime.Now;
                                insert.AppendChild(text);

                                bookmarkText.AppendChild(insert);

                                //   bookmarkText.Append(insert);

                            }

2)表格单元格

   foreach (var table in tables)
                {
                    if (content.TableData.Count <= index) break;

                    List> lstData = content.TableData[index].TableData;
                    index++;
                    // 添加数据
                    foreach (List rowArray in lstData)
                    {
                        TableRow row = new TableRow();
                        foreach (string strCell in rowArray)
                        {
                            TableCell cell = new TableCell();

                            Text text = new Text(strCell);
                            RunProperties runProperties = new RunProperties();
                            InsertedRun insert = new InsertedRun(runProperties);
                            insert.Id = Guid.NewGuid().ToString();

                            insert.Author = new StringValue() { Value = "王大大222" };
                            insert.Date = DateTime.Now;
                            insert.AppendChild(text);

                           

                            cell.Append(new Paragraph(new Run(insert)));
                         //   cell.Append(insert);
                            row.Append(cell);
                        }
                        table.Append(row);
                    }

                    // TableRow tr = WordUtil.DOC_TAB_GetTableRow(ref table, 0);
                }

 

你可能感兴趣的:(.NET)