Office Integration.Word 를 사용 하여 lightswitch 에서 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 를 다이나믹 으로 직접 조작 합 니 다.
현재 해결 해 야 할 문 제 는 출력 날짜 형식 입 니 다.한 가지 방법 은 데이터 원본 에서 원 하 는 형식(문자 형식)으로 포맷 하 는 것 입 니 다.다른 하 나 는 템 플 릿 에서 방법 을 생각해 볼 수 밖 에 없습니다.
효 과 는 아래 그림 과 같다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Access Request, Session and Application in Struts2If we want to use request, Session and application in JSP, what should we do? We can obtain Map type objects such as Req...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.