Office Integration.Word 를 사용 하여 lightswitch 에서 WORD 내 보 내기 기능(계속)

이전 문서 에서 먼저 템 플 릿 을 설정 한 다음 에 Office Integration 패 키 지 를 이용 하여 템 플 릿 을 호출 하고 해당 하 는 데 이 터 를 출력 했다.본 고 는 이 를 바탕 으로 WORD 에 대해 표 통합 기능 을 작 동 했 으 나 일부 기능 을 시도 하고 있다.
 
   partial void GenerateDocument_Execute()
        {
            // Write your code here.
            string path= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            Assembly ass = Assembly.GetExecutingAssembly();
            Stream s = ass.GetManifestResourceStream(this.GetType(), "MonthPlan.docx");
            byte[] bt = new byte[s.Length];
            s.Read(bt, 0, bt.Length);
            s.Close();
            s.Dispose();
            var fileName = this.WorkPlanHeads.SelectedItem.PlanYearMonth + "    ";
            FileStream fs = new FileStream(path + "\\"+fileName+".docx", FileMode.Create);
            fs.Write(bt, 0, bt.Length);
            fs.Close();
            fs.Dispose();
         
            List<OfficeIntegration.ColumnMapping> planHeadColumn = new List<ColumnMapping>() { 
                new ColumnMapping("PlanYear","PlanYear"),
                    new ColumnMapping("PlanMonth","PlanMonth"),
                    new ColumnMapping("FillDate","FillDate")
            };
            dynamic doc = OfficeIntegration.Word.GenerateDocument(path + "\\"+ fileName+".docx", this.WorkPlanHeads.SelectedItem, planHeadColumn);
            List<string> detailsHeader = new List<string>() { 
                "" ,"TypeName","PlanContent","WorkEmp","WorkDept","PlanEndDate","Remark"
            };
            
            OfficeIntegration.Word.ExportEntityCollection(doc, "PlanDetail", 2, false, this.WorkPlanHeads.SelectedItem.WorkPlanDetails, detailsHeader);
      //      OfficeIntegration.Word.SaveAsPDF(doc, path + "\\" + fileName + ".pdf", true);
            string preStr="",curStr="";
            int indexStart = 2, indexEnd = 2; //VBA   1  +   
            var table = doc.Tables(1); //       

            for (int i = 2; i < table.Rows.Count+1; i++)
            {
                curStr = doc.Tables(1).Cell(i, 2).Range.Text;//        ,         
                if (curStr == preStr)
                {
                    indexEnd = i;
                    table.Cell(i - 1, 2).Range.Text = "";//         
                    if (i == table.Rows.Count)
                    {
                        if (indexEnd > indexStart) 
                            table.Cell(indexStart, 2).Merge(table.Cell(indexEnd, 2));
                    }
                   
                }
                else
                {
                    
                    if (indexEnd > indexStart)
                        table.Cell(indexStart,2).Merge(table.Cell(indexEnd,2));
                    indexStart = i;
                }
                preStr = curStr;
            }
            doc.Save();//      
        }

  
VBA 를 사용 하여 템 플 릿 문서 에서 통합 작업 을 수행 하려 고 했 습 니 다.그러나 안전성 문 제 를 고려 해 이 를 포기 했다.클 라 이언 트 WORD 를 다이나믹 으로 직접 조작 합 니 다.
 
현재 해결 해 야 할 문 제 는 출력 날짜 형식 입 니 다.한 가지 방법 은 데이터 원본 에서 원 하 는 형식(문자 형식)으로 포맷 하 는 것 입 니 다.다른 하 나 는 템 플 릿 에서 방법 을 생각해 볼 수 밖 에 없습니다.
효 과 는 아래 그림 과 같다.

좋은 웹페이지 즐겨찾기