コード例 #1
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "入學照片")
            {
                byte[] photo = e.FieldValue as byte[];
                if (photo == null)
                {
                    return;
                }
                DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                photoBuilder.MoveToField(e.Field, true);
                e.Field.Remove();

                Shape photoShape = new Shape(e.Document, ShapeType.Image);
                photoShape.ImageData.SetImage(photo);
                double shapeHeight = 0;
                double shapeWidth  = 0;
                photoShape.WrapType = WrapType.Inline;//設定文繞圖

                //resize

                double origSizeRatio = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
                Cell   curCell       = photoBuilder.CurrentParagraph.ParentNode as Cell;
                shapeHeight       = (curCell.ParentNode as Row).RowFormat.Height;
                shapeWidth        = curCell.CellFormat.Width;
                photoShape.Height = shapeHeight;
                photoShape.Width  = shapeWidth;
                photoBuilder.InsertNode(photoShape);
            }
        }
コード例 #2
0
        private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 處理照片
            if (e.FieldName == "照片")
            {
                DocumentBuilder builder1 = new DocumentBuilder(e.Document);
                builder1.MoveToField(e.Field, true);

                byte[] photoBytes = null;
                try
                {
                    photoBytes = Convert.FromBase64String("" + e.FieldValue);
                }
                catch (Exception ex)
                {
                    //builder1.Write("照片粘貼處");
                    e.Field.Remove();
                    return;
                }

                if (photoBytes == null || photoBytes.Length == 0)
                {
                    //builder1.Write("照片粘貼處");
                    e.Field.Remove();
                    return;
                }

                e.Field.Remove();

                Shape photoShape = new Shape(e.Document, ShapeType.Image);
                photoShape.ImageData.SetImage(photoBytes);
                photoShape.WrapType = WrapType.Inline;

                #region AutoResize

                double origHWRate  = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
                double shapeHeight = (builder1.CurrentParagraph.ParentNode.ParentNode as Row).RowFormat.Height;
                double shapeWidth  = (builder1.CurrentParagraph.ParentNode as Cell).CellFormat.Width;
                if ((shapeHeight / shapeWidth) < origHWRate)
                {
                    shapeWidth = shapeHeight / origHWRate;
                }
                else
                {
                    shapeHeight = shapeWidth * origHWRate;
                }

                #endregion

                photoShape.Height = shapeHeight * 0.9;
                photoShape.Width  = shapeWidth * 0.9;

                builder1.InsertNode(photoShape);
            }
            #endregion
        }
コード例 #3
0
ファイル: Report.cs プロジェクト: ischoolinc/SHBehavior
        private void DisciplineNotification_MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region MailMerge_MergeField
            if (e.FieldName == "懲戒明細")
            {
                object[]      objectValues = (object[])e.FieldValue;
                List <string> eachStudentDisciplineDetail = (List <string>)objectValues[0];

                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(e.Document);

                builder.MoveToField(e.Field, false);
                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.CellFormat.Borders.ClearFormatting();
                builder.CellFormat.VerticalAlignment = Aspose.Words.CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding       = 3.0;
                builder.RowFormat.LeftIndent         = 0.0;
                builder.RowFormat.Height             = 15.0;

                int rowNumber = 5;
                if (eachStudentDisciplineDetail.Count > rowNumber * 2)
                {
                    rowNumber  = eachStudentDisciplineDetail.Count / 2;
                    rowNumber += eachStudentDisciplineDetail.Count % 2;
                }

                if (eachStudentDisciplineDetail.Count > rowNumber * 2)
                {
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) / 2;
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) % 2;
                }

                for (int j = 0; j < rowNumber; j++)
                {
                    builder.InsertCell();
                    builder.CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.Single;
                    builder.CellFormat.Borders.Right.Color     = Color.Black;
                    if (j < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j]);
                    }
                    builder.InsertCell();
                    if (j + rowNumber < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j + rowNumber]);
                    }
                    builder.EndRow();
                }

                builder.EndTable();

                e.Text = string.Empty;
            }
            #endregion
        }
コード例 #4
0
 void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
 {
 }
コード例 #5
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "新生照片1" || e.FieldName == "新生照片2")
            {
                #region 新生照片
                if (!string.IsNullOrEmpty(e.FieldValue.ToString()))
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                        //cell.CellFormat.LeftPadding = 0;
                        //cell.CellFormat.RightPadding = 0;
                        if (e.FieldName == "新生照片1")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        //paragraph.AppendChild(photoShape);
                        photoBuilder.InsertNode(photoShape);
                    }
                }
                #endregion
            }
            else if (e.FieldName == "畢業照片1" || e.FieldName == "畢業照片2")
            {
                #region 畢業照片
                if (!string.IsNullOrEmpty(e.FieldValue.ToString()))
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                        //cell.CellFormat.LeftPadding = 0;
                        //cell.CellFormat.RightPadding = 0;
                        if (e.FieldName == "畢業照片1")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        //paragraph.AppendChild(photoShape);
                        photoBuilder.InsertNode(photoShape);
                    }
                }
                #endregion
            }
            else if (e.FieldName == "資料")
            {
                List <ResultScoreRecord> records = (List <ResultScoreRecord>)e.FieldValue;
                records.Sort(SortResultScore);

                Document PageOne = e.Document; // (Document)_template.Clone(true);
                _run = new Run(PageOne);
                DocumentBuilder builder = new DocumentBuilder(PageOne);
                builder.MoveToMergeField("資料");
                ////取得目前Cell
                Cell cell = (Cell)builder.CurrentParagraph.ParentNode;
                ////取得目前Row
                Row row = (Row)builder.CurrentParagraph.ParentNode.ParentNode;

                //建立新行
                for (int x = 1; x < records.Count; x++)
                {
                    (cell.ParentNode.ParentNode as Table).InsertAfter(row.Clone(true), cell.ParentNode);
                }

                foreach (ResultScoreRecord obj in records)
                {
                    List <string> list = new List <string>();
                    list.Add(obj.SchoolYear.ToString());
                    list.Add(obj.Semester.ToString());
                    list.Add(obj.ClubName);
                    list.Add(obj.CadreName);

                    foreach (string listEach in list)
                    {
                        Write(cell, listEach);

                        if (cell.NextSibling != null)        //是否最後一格
                        {
                            cell = cell.NextSibling as Cell; //下一格
                        }
                    }

                    Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一個Row
                    if (Nextrow == null)
                    {
                        break;
                    }
                    cell = Nextrow.FirstCell; //第一格Cell
                }
            }
            else
            {
                //...
            }
        }
コード例 #6
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "各學期成績")
            {
                e.Text = string.Empty;

                Student         stu     = (Student)e.FieldValue;
                DocumentBuilder builder = new DocumentBuilder(e.Document);
                //有成績之學期
                List <int> semesters = new List <int>();
                #region 總計此學生有學期成績之學期
                foreach (SubjectInfo subject in stu.SubjectCollection.Values)
                {
                    foreach (int sem in subject.SemsScores.Keys)
                    {
                        if (!semesters.Contains(sem))
                        {
                            semesters.Add(sem);
                        }
                    }
                }
                foreach (EntryInfo entry in stu.EntryCollection.Values)
                {
                    foreach (int sem in entry.SemsScores.Keys)
                    {
                        if (!semesters.Contains(sem))
                        {
                            semesters.Add(sem);
                        }
                    }
                }
                #endregion
                semesters.Sort();

                builder.MoveToField(e.Field, false);
                #region 取得外框寬度並計算欄寬
                Cell   SCell     = (Cell)builder.CurrentParagraph.ParentNode;
                double Swidth    = SCell.CellFormat.Width;
                double microUnit = Swidth / (semesters.Count + 6);   //每學期給一份,總平均給一份,百分比給一份,班級排名及科目各給兩份
                #endregion
                Table table = builder.StartTable();

                builder.CellFormat.ClearFormatting();
                builder.CellFormat.Borders.LineWidth = 0.5;

                builder.RowFormat.HeightRule            = HeightRule.Auto;
                builder.RowFormat.Height                = builder.Font.Size * 1.2d;
                builder.RowFormat.Alignment             = RowAlignment.Center;
                builder.CellFormat.VerticalAlignment    = CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding          = 3.0;
                builder.CellFormat.RightPadding         = 3.0;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                builder.ParagraphFormat.LineSpacing     = 10;
                //builder.Font.Size = 8;

                List <EntryInfo> entries = new List <EntryInfo>();
                entries.AddRange(stu.EntryCollection.Values);
                entries.Sort(new EntryComparer());
                if (entries.Count > 0)
                {
                    #region 填表頭
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("分項總成績");
                    foreach (int sem in semesters)
                    {
                        #region 每學期給一欄
                        builder.InsertCell().CellFormat.Width = microUnit;
                        builder.CellFormat.Borders.Right.LineWidth = 0.25;
                        switch (sem)
                        {
                        case 1:
                            builder.Write("一上");
                            break;

                        case 2:
                            builder.Write("一下");
                            break;

                        case 3:
                            builder.Write("二上");
                            break;

                        case 4:
                            builder.Write("二下");
                            break;

                        case 5:
                            builder.Write("三上");
                            break;

                        case 6:
                            builder.Write("三下");
                            break;

                        case 7:
                            builder.Write("四上");
                            break;

                        case 8:
                            builder.Write("四下");
                            break;

                        default:
                            builder.Write("第" + sem + "學期");
                            break;
                        }
                        #endregion
                    }
                    builder.InsertCell().CellFormat.Width = microUnit * 1.5;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("總平均");
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("班級排名");
                    builder.InsertCell().CellFormat.Width = microUnit;
                    builder.Write("百分比");
                    builder.EndRow();
                    #endregion
                    //分項跟科目成績中間劃雙線
                    foreach (Cell cell in table.LastRow.Cells)
                    {
                        cell.CellFormat.Shading.BackgroundPatternColor = Color.LightGray;
                    }
                }
                //分項跟科目成績中間劃雙線
                //foreach ( Cell cell in table.LastRow.Cells )
                //    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.Double;
                #region 填分項成績
                foreach (EntryInfo entryInfo in entries)
                {
                    //科目名稱
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write(entryInfo.Name);
                    #region 每學期成績
                    foreach (int sem in semesters)
                    {
                        builder.InsertCell().CellFormat.Width = microUnit;
                        builder.CellFormat.Borders.Right.LineWidth = 0.25;
                        if (entryInfo.SemsScores.ContainsKey(sem))
                        {
                            builder.Write("" + entryInfo.SemsScores[sem]);
                        }
                    }
                    #endregion
                    //總平均
                    builder.InsertCell().CellFormat.Width = microUnit * 1.5;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    if (entryInfo.Name == "德行")
                    {
                        decimal moral_score = Math.Round(entryInfo.GetAverange());
                        builder.Write("" + moral_score + " (" + GetMoralLevel(moral_score) + "級分)");
                    }
                    else
                    {
                        builder.Write("" + entryInfo.GetAverange());
                    }
                    //班級排名
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("" + entryInfo.Place + " / " + entryInfo.Radix);
                    //百分比
                    builder.InsertCell().CellFormat.Width = microUnit;
                    builder.Write("" + entryInfo.GetPercentage() + "%");
                    builder.EndRow();
                }
                #endregion

                List <SubjectInfo> subjects = new List <SubjectInfo>();
                subjects.AddRange(stu.SubjectCollection.Values);
                subjects.Sort(new SubjectComparer());
                if (subjects.Count > 0)
                {
                    #region 填表頭
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("科目成績");
                    foreach (int sem in semesters)
                    {
                        #region 每學期給一欄
                        builder.InsertCell().CellFormat.Width = microUnit;
                        builder.CellFormat.Borders.Right.LineWidth = 0.25;
                        switch (sem)
                        {
                        case 1:
                            builder.Write("一上");
                            break;

                        case 2:
                            builder.Write("一下");
                            break;

                        case 3:
                            builder.Write("二上");
                            break;

                        case 4:
                            builder.Write("二下");
                            break;

                        case 5:
                            builder.Write("三上");
                            break;

                        case 6:
                            builder.Write("三下");
                            break;

                        case 7:
                            builder.Write("四上");
                            break;

                        case 8:
                            builder.Write("四下");
                            break;

                        default:
                            builder.Write("第" + sem + "學期");
                            break;
                        }
                        #endregion
                    }
                    builder.InsertCell().CellFormat.Width = microUnit * 1.5;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("總平均");
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("班級排名");
                    builder.InsertCell().CellFormat.Width = microUnit;
                    builder.Write("百分比");
                    builder.EndRow();
                    #endregion
                    //分項跟科目成績中間劃雙線
                    foreach (Cell cell in table.LastRow.Cells)
                    {
                        cell.CellFormat.Shading.BackgroundPatternColor = Color.LightGray;
                    }
                    //分項跟科目成績中間劃雙線
                    //foreach ( Cell cell in table.LastRow.Cells )
                    //    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.Double;
                }
                #region 填科目成績

                foreach (SubjectInfo subjectInfo in subjects)
                {
                    //科目名稱
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write(subjectInfo.Name);
                    #region 每學期成績
                    foreach (int sem in semesters)
                    {
                        builder.InsertCell().CellFormat.Width = microUnit;
                        builder.CellFormat.Borders.Right.LineWidth = 0.25;
                        if (subjectInfo.SemsScores.ContainsKey(sem))
                        {
                            builder.Write("" + subjectInfo.SemsScores[sem]);
                        }
                    }
                    #endregion
                    //總平均
                    builder.InsertCell().CellFormat.Width = microUnit * 1.5;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("" + subjectInfo.GetAverange());
                    //班級排名
                    builder.InsertCell().CellFormat.Width = microUnit * 2;
                    builder.CellFormat.Borders.Right.LineWidth = 0.25;
                    builder.Write("" + subjectInfo.Place + " / " + subjectInfo.Radix);
                    //百分比
                    builder.InsertCell().CellFormat.Width = microUnit;
                    builder.Write("" + subjectInfo.GetPercentage() + "%");
                    builder.EndRow();
                }
                #endregion
                #region 去除表格四邊的線
                if (table.FirstRow != null)
                {
                    foreach (Cell cell in table.FirstRow.Cells)
                    {
                        cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                    }
                }

                if (table.LastRow != null)
                {
                    foreach (Cell cell in table.LastRow.Cells)
                    {
                        cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                    }
                }

                foreach (Row row in table.Rows)
                {
                    row.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                    row.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                }
                #endregion
            }
            //int row_index = 1;

            ////排序科目
            //List<SubjectInfo> subject_list = new List<SubjectInfo>();
            //subject_list.AddRange(each_stu.SubjectCollection.Values);
            //subject_list.Sort(new SubjectComparer());

            ////排序分項
            //List<EntryInfo> entry_list = new List<EntryInfo>();
            //entry_list.AddRange(each_stu.EntryCollection.Values);
            //entry_list.Sort(new EntryComparer());

            ////填入科目
            //foreach ( SubjectInfo info in subject_list )
            //{
            //    run.Text = info.Name;

            //    subject_table.Rows[row_index].Cells[0].Paragraphs[0].Runs.Add(run.Clone(true));

            //    foreach ( int sems_index in info.SemsScores.Keys )
            //    {
            //        run.Text = info.SemsScores[sems_index].ToString();
            //        subject_table.Rows[row_index].Cells[sems_index].Paragraphs[0].Runs.Add(run.Clone(true));
            //    }
            //    //平均
            //    run.Text = info.GetAverange().ToString();
            //    subject_table.Rows[row_index].Cells[9].Paragraphs[0].Runs.Add(run.Clone(true));
            //    //排名
            //    run.Text = "" + info.Place + " / " + info.Radix;
            //    subject_table.Rows[row_index].Cells[10].Paragraphs[0].Runs.Add(run.Clone(true));
            //    //百分比
            //    run.Text = "" + info.GetPercentage() + "%";
            //    subject_table.Rows[row_index].Cells[11].Paragraphs[0].Runs.Add(run.Clone(true));

            //    row_index++;
            //}

            //row_index = 0;

            ////填入分項
            //foreach ( EntryInfo info in entry_list )
            //{
            //    run.Text = info.Name;

            //    entry_table.Rows[row_index].Cells[0].Paragraphs[0].Runs.Add(run.Clone(true));

            //    foreach ( int sems_index in info.SemsScores.Keys )
            //    {
            //        run.Text = info.SemsScores[sems_index].ToString();
            //        entry_table.Rows[row_index].Cells[sems_index].Paragraphs[0].Runs.Add(run.Clone(true));
            //    }
            //    //平均
            //    run.Text = info.GetAverange().ToString();
            //    entry_table.Rows[row_index].Cells[9].Paragraphs[0].Runs.Add(run.Clone(true));
            //    //排名
            //    run.Text = "" + info.Place + " / " + info.Radix;
            //    entry_table.Rows[row_index].Cells[10].Paragraphs[0].Runs.Add(run.Clone(true));
            //    //百分比
            //    run.Text = "" + info.GetPercentage() + "%";
            //    entry_table.Rows[row_index].Cells[11].Paragraphs[0].Runs.Add(run.Clone(true));

            //    row_index++;
            //}
        }
コード例 #7
0
ファイル: Report.cs プロジェクト: ratalai/JHCore_Bilingual
        private void AbsenceNotification_MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 缺曠明細
            if (e.FieldName == "缺曠明細")
            {
                if (e.FieldValue == null)
                {
                    return;
                }

                object[] objectValues = (object[])e.FieldValue;
                Dictionary <string, Dictionary <string, string> > studentAbsenceDetail = (Dictionary <string, Dictionary <string, string> >)objectValues[0];
                List <string> periodList = (List <string>)objectValues[1];

                DocumentBuilder builder = new DocumentBuilder(e.Document);

                #region 缺曠明細部份
                builder.MoveToField(e.Field, false);
                Cell detailStartCell     = (Cell)builder.CurrentParagraph.ParentNode;
                Row  detailStartRow      = (Row)detailStartCell.ParentNode;
                int  detailStartRowIndex = e.Document.Sections[0].Body.Tables[0].IndexOf(detailStartRow);

                Table detailTable = builder.StartTable();
                builder.CellFormat.Borders.Left.LineWidth  = 0.5;
                builder.CellFormat.Borders.Right.LineWidth = 0.5;

                builder.RowFormat.HeightRule = HeightRule.Auto;
                builder.RowFormat.Height     = 12;
                builder.RowFormat.Alignment  = RowAlignment.Center;

                int rowNumber = 4; //共4個Row,依缺曠天數進行調整
                if (studentAbsenceDetail.Count > rowNumber * 3)
                {
                    rowNumber = studentAbsenceDetail.Count / 3;
                    if (studentAbsenceDetail.Count % 3 > 0)
                    {
                        rowNumber++;
                    }
                }

                #region 暫解阿!!
                int TestPeriodListCount = periodList.Count;
                if (periodList.Count < 10)
                {
                    TestPeriodListCount = 10;
                }
                else
                {
                    TestPeriodListCount = periodList.Count;
                }
                #endregion

                builder.InsertCell();

                #region 填入日期 & 節次
                for (int i = 0; i < 3; i++)
                {
                    builder.CellFormat.Borders.Right.Color = Color.Black;
                    builder.CellFormat.Borders.Left.Color  = Color.Black;
                    builder.CellFormat.Width             = 20;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
                    builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                    builder.Write("日期");
                    builder.InsertCell();

                    for (int j = 0; j < TestPeriodListCount; j++)
                    {
                        builder.CellFormat.Borders.Right.Color = Color.Black;
                        builder.CellFormat.Borders.Left.Color  = Color.Black;
                        builder.CellFormat.Borders.LineStyle   = LineStyle.Dot;
                        builder.CellFormat.Width       = 9;
                        builder.CellFormat.WrapText    = true;
                        builder.CellFormat.LeftPadding = 0.5;
                        if (j < periodList.Count)
                        {
                            builder.Write(periodList[j]); //寫入節次名稱
                        }
                        builder.InsertCell();
                    }
                }
                #endregion

                builder.EndRow();

                #region 建立每日格數
                for (int x = 0; x < rowNumber; x++)
                {
                    builder.CellFormat.Borders.Right.Color      = Color.Black;
                    builder.CellFormat.Borders.Left.Color       = Color.Black;
                    builder.CellFormat.Borders.Left.LineWidth   = 0.5;
                    builder.CellFormat.Borders.Right.LineWidth  = 0.5;
                    builder.CellFormat.Borders.Top.LineWidth    = 0.5;
                    builder.CellFormat.Borders.Bottom.LineWidth = 0.5;
                    builder.CellFormat.Borders.LineStyle        = LineStyle.Dot;
                    builder.RowFormat.HeightRule = HeightRule.Exactly;
                    builder.RowFormat.Height     = 12;
                    builder.RowFormat.Alignment  = RowAlignment.Center;
                    builder.InsertCell();

                    for (int i = 0; i < 3; i++)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Width = 20;
                        builder.Write("");
                        builder.InsertCell();

                        builder.CellFormat.Borders.LineStyle = LineStyle.Dot;

                        for (int j = 0; j < TestPeriodListCount; j++)
                        {
                            builder.CellFormat.Width = 9;
                            builder.Write("");
                            builder.InsertCell();
                        }
                    }

                    builder.EndRow();
                }
                #endregion

                builder.EndTable();

                foreach (Cell var in detailTable.Rows[0].Cells)
                {
                    var.Paragraphs[0].ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                    var.Paragraphs[0].ParagraphFormat.LineSpacing     = 9;
                }
                #endregion

                #region 填寫缺曠明細
                int eachDetailRowIndex = 0;
                int eachDetailColIndex = 0;

                foreach (string date in studentAbsenceDetail.Keys)
                {
                    int       eachDetailPeriodColIndex = eachDetailColIndex + 1;
                    string[]  splitDate     = date.Split('/');
                    Paragraph dateParagraph = detailTable.Rows[eachDetailRowIndex + 1].Cells[eachDetailColIndex].Paragraphs[0];
                    dateParagraph.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                    dateParagraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                    dateParagraph.ParagraphFormat.LineSpacing     = 9;

                    dateParagraph.Runs.Clear();
                    dateParagraph.Runs.Add(new Run(e.Document));
                    dateParagraph.Runs[0].Font.Size = 8;
                    dateParagraph.Runs[0].Text      = splitDate[1] + "/" + splitDate[2];

                    foreach (string period in periodList)
                    {
                        string dataValue = "";
                        if (studentAbsenceDetail[date].ContainsKey(period))
                        {
                            dataValue = studentAbsenceDetail[date][period];
                            Cell miniCell = detailTable.Rows[eachDetailRowIndex + 1].Cells[eachDetailPeriodColIndex];
                            miniCell.Paragraphs.Clear();
                            miniCell.Paragraphs.Add(dateParagraph.Clone(true));
                            miniCell.Paragraphs[0].Runs[0].Font.Size = 14 - (int)(TestPeriodListCount / 2); //依表格多寡縮小文字
                            if (absenceList.ContainsKey(dataValue))
                            {
                                miniCell.Paragraphs[0].Runs[0].Text = absenceList[dataValue];
                            }
                            else
                            {
                                miniCell.Paragraphs[0].Runs[0].Text = "";
                            }
                        }
                        eachDetailPeriodColIndex++;
                    }
                    eachDetailRowIndex++;
                    if (eachDetailRowIndex >= rowNumber)
                    {
                        eachDetailRowIndex  = 0;
                        eachDetailColIndex += (TestPeriodListCount + 1);
                    }
                }
                #endregion

                e.Text = string.Empty;
            }
            #endregion
        }
コード例 #8
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "照片")
            {
                byte[] photo = e.FieldValue as byte[];
                if (photo == null)
                {
                    return;
                }
                DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                photoBuilder.MoveToField(e.Field, true);
                e.Field.Remove();

                Shape photoShape = new Shape(e.Document, ShapeType.Image);
                photoShape.ImageData.SetImage(photo);
                double shapeHeight = 0;
                double shapeWidth  = 0;
                if (UseCountyType == CountyType.高雄)
                {
                    photoShape.WrapType = WrapType.Inline;//設定文繞圖

                    //resize
                    double origSizeRatio = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
                    Cell   curCell       = photoBuilder.CurrentParagraph.ParentNode as Cell;
                    shapeHeight = (curCell.ParentNode as Row).RowFormat.Height * 4;
                    shapeWidth  = curCell.CellFormat.Width;

                    if ((shapeHeight / shapeWidth) < origSizeRatio)
                    {
                        shapeWidth = shapeHeight / origSizeRatio;
                    }
                    else
                    {
                        shapeHeight = shapeWidth * origSizeRatio;
                    }

                    //double origSizeRatio = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
                    //Cell curCell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                    ////shapeHeight = (curCell.ParentNode as Row).RowFormat.Height * 4;
                    //shapeHeight = (curCell.ParentNode as Row).RowFormat.Height;
                    //shapeWidth = curCell.CellFormat.Width;
                }

                if (UseCountyType == CountyType.新竹)
                {
                    photoShape.WrapType = WrapType.Inline;//設定文繞圖

                    //resize
                    double origSizeRatio = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints;
                    Cell   curCell       = photoBuilder.CurrentParagraph.ParentNode as Cell;
                    //shapeHeight = (curCell.ParentNode as Row).RowFormat.Height * 4;
                    shapeHeight = (curCell.ParentNode as Row).RowFormat.Height;
                    shapeWidth  = curCell.CellFormat.Width;

                    //if ((shapeHeight / shapeWidth) < origSizeRatio)
                    //    shapeWidth = shapeHeight / origSizeRatio;
                    //else
                    //    shapeHeight = shapeWidth * origSizeRatio;
                }

                photoShape.Height = shapeHeight;
                photoShape.Width  = shapeWidth;
                //photoShape.Top = 28;


                photoBuilder.InsertNode(photoShape);
            }

            if (e.FieldName == "條碼")
            {
                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, true); //將游標移到條碼所在欄位
                e.Field.Remove();                   //將原先的合併欄位刪除

                BarCodeBuilder bb = new BarCodeBuilder();
                if (e.FieldValue != null)
                {
                    if (e.FieldValue.ToString() != "")
                    {
                        bb.CodeText = e.FieldValue.ToString();


                        bb.SymbologyType = Symbology.Code128;
                    }
                    else
                    {
                        bb.CodeLocation = CodeLocation.None;//不輸出學號
                    }
                }

                bb.xDimension = 0.5f;
                bb.BarHeight  = 4.0f;


                MemoryStream stream = new MemoryStream();
                bb.Save(stream, ImageFormat.Jpeg); //將產生出的條碼存成圖檔

                builder.InsertImage(stream);       //
            }
        }
コード例 #9
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "Data")
            {
                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, true);
                e.Field.Remove();

                //取得學生ID/日期/缺曠資料
                Dictionary <string, Dictionary <string, Dictionary <string, string> > > dic = Data.allAbsenceDetail[e.FieldValue.ToString()] as Dictionary <string, Dictionary <string, Dictionary <string, string> > >;

                List <StudentRecord> StudentSortList = new List <StudentRecord>();
                foreach (string each in dic.Keys) //取得學生ID
                {
                    StudentRecord sr = Data.studentInfoDict[each];
                    if (!StudentSortList.Contains(sr))
                    {
                        StudentSortList.Add(sr);
                    }
                }
                StudentSortList.Sort(new Comparison <StudentRecord>(StudentComparer));

                //插入於此Row之下
                Row  refrow    = builder.CurrentParagraph.ParentNode.ParentNode as Row;
                Cell SplieCell = GetMoveRightCell(refrow.Cells[0], 3);
                CellSplit(SplieCell, periodList.Count);

                //範本
                Row rowtemp = builder.CurrentParagraph.ParentNode.ParentNode.Clone(true) as Row;

                //此表格
                Table table = builder.CurrentParagraph.ParentNode.ParentNode.ParentNode as Table;

                foreach (StudentRecord each in StudentSortList) //取得學生ID
                {
                    StudentRecord sr = each;

                    #region 排一下日期

                    List <string> DatList = new List <string>();
                    foreach (string each2 in dic[sr.ID].Keys) //日期
                    {
                        DatList.Add(each2);
                    }

                    DatList.Sort(sortdat);

                    #endregion


                    foreach (string each2 in DatList) //日期
                    {
                        //如果該日期為0節資料,就不列印(因為被設定檔過慮掉)
                        if (dic[sr.ID][each2].Count == 0)
                        {
                            continue;
                        }

                        Write(refrow.Cells[ColumnIndex["座號"]], sr.SeatNo.HasValue ? sr.SeatNo.Value.ToString() : ""); //座號
                        Write(refrow.Cells[ColumnIndex["姓名"]], sr.Name);                                              //姓名
                        Write(refrow.Cells[ColumnIndex["日期"]], each2);                                                //日期

                        foreach (string each3 in dic[sr.ID][each2].Keys)                                              //節次
                        {
                            if (ColumnIndex.ContainsKey(each3))
                            {
                                Write(refrow.Cells[ColumnIndex[each3]], dic[sr.ID][each2][each3]);
                            }
                        }
                        refrow = table.InsertAfter(rowtemp.Clone(true), refrow) as Row;
                    }
                }

                refrow.Remove();
            }
        }
コード例 #10
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "照片" || e.FieldName == "照片2")
            {
                if (e.FieldValue != null)
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                        //cell.CellFormat.LeftPadding = 0;
                        //cell.CellFormat.RightPadding = 0;
                        if (e.FieldName == "照片")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        //paragraph.AppendChild(photoShape);
                        photoBuilder.InsertNode(photoShape);
                    }
                }
            }

            if (e.FieldName == "畢業照片" || e.FieldName == "畢業照片2")
            {
                if (e.FieldValue != null)
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        //Paragraph paragraph = photoBuilder.InsertParagraph();// new Paragraph(e.Document);
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        //Cell cell = photoBuilder.CurrentParagraph.ParentNode as Cell;
                        //cell.CellFormat.LeftPadding = 0;
                        //cell.CellFormat.RightPadding = 0;
                        if (e.FieldName == "畢業照片")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        //paragraph.AppendChild(photoShape);
                        photoBuilder.InsertNode(photoShape);
                    }
                }
            }

            if (e.FieldName == "條碼")
            {
                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, true);
                e.Field.Remove();
                BarCodeBuilder bb = new BarCodeBuilder();
                if (e.FieldValue != null && e.FieldValue.ToString() != "")
                {
                    bb.CodeText      = e.FieldValue.ToString();
                    bb.SymbologyType = Symbology.Code128;
                    bb.CodeLocation  = CodeLocation.None;
                    bb.xDimension    = 0.5f;
                    bb.BarHeight     = 6.0f;
                    MemoryStream stream = new MemoryStream();
                    bb.Save(stream, ImageFormat.Jpeg);
                    builder.InsertImage(stream);
                }
            }
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: imcloudwu/ClubProofReport
        //MailMerge事件
        private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "新生照片1" || e.FieldName == "新生照片2")
            {
                if (!string.IsNullOrEmpty(e.FieldValue.ToString()))
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        if (e.FieldName == "新生照片1")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        photoBuilder.InsertNode(photoShape);
                    }
                }
            }
            else if (e.FieldName == "畢業照片1" || e.FieldName == "畢業照片2")
            {
                if (!string.IsNullOrEmpty(e.FieldValue.ToString()))
                {
                    byte[] photo = Convert.FromBase64String(e.FieldValue.ToString()); //e.FieldValue as byte[];

                    if (photo != null && photo.Length > 0)
                    {
                        DocumentBuilder photoBuilder = new DocumentBuilder(e.Document);
                        photoBuilder.MoveToField(e.Field, true);
                        e.Field.Remove();
                        Shape photoShape = new Shape(e.Document, ShapeType.Image);
                        photoShape.ImageData.SetImage(photo);
                        photoShape.WrapType = WrapType.Inline;
                        if (e.FieldName == "畢業照片1")
                        {
                            // 1吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(25);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(35);
                        }
                        else
                        {
                            //2吋
                            photoShape.Width  = ConvertUtil.MillimeterToPoint(35);
                            photoShape.Height = ConvertUtil.MillimeterToPoint(45);
                        }
                        photoBuilder.InsertNode(photoShape);
                    }
                }
            }
        }
コード例 #12
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 科目成績

            if (e.FieldName == "科目成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> > subjectScore = (Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> >)objectValue[0];
                string        resitSign  = (string)objectValue[1];
                string        repeatSign = (string)objectValue[2];
                StudentRecord studRec    = (StudentRecord)objectValue[3];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table SSTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int SSRowNumber     = SSTable.Rows.Count - 1;
                int SSTableRowIndex = 1;
                int SSTableColIndex = 0;
                int MaxSubjectCount = SSRowNumber * 2;

                try
                {
                    // 當科目數超過範本可存放數,不列入處理
                    if (subjectScore.Keys.Count > MaxSubjectCount)
                    {
                        if (_ErrorMessage.Length < 1)
                        {
                            _ErrorMessage.AppendLine("產生資料發生錯誤:學生成績科目數超過範本可顯示科目數:" + MaxSubjectCount + " ,請調整範本科目數後再列印");
                        }

                        string className = "";
                        if (studRec.RefClass != null)
                        {
                            className = studRec.RefClass.ClassName;
                        }
                        string ErrMsg = "學號:" + studRec.StudentNumber + ",班級:" + className + "座號:" + studRec.SeatNo + ",姓名:" + studRec.StudentName + ", 學生成績科目數:" + subjectScore.Keys.Count;
                        _ErrorMessage.AppendLine(ErrMsg);
                    }
                    else
                    {
                        List <SemesterSubjectScoreInfo> sortList = new List <SemesterSubjectScoreInfo>();
                        sortList.AddRange(subjectScore.Keys);
                        sortList.Sort(SortBySemesterSubjectScoreInfo);

                        foreach (SemesterSubjectScoreInfo info in sortList)
                        {
                            Runs runs = SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex].Paragraphs[0].Runs;
                            runs.Add(new Run(e.Document));
                            runs[runs.Count - 1].Text      = subjectScore[info]["科目"] + ((string.IsNullOrEmpty(subjectScore[info]["級別"])) ? "" : (" (" + subjectScore[info]["級別"] + ")"));
                            runs[runs.Count - 1].Font.Size = 10;
                            runs[runs.Count - 1].Font.Name = "新細明體";

                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["必修"] + subjectScore[info]["學分"]));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["分數"]));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs[0].Font.Size = 10;

                            int    colshift = 0;
                            string re       = "";
                            if (subjectScore[info].ContainsKey("補考"))
                            {
                                if (subjectScore[info]["補考"] == "是")
                                {
                                    re = resitSign;
                                }
                                else if (subjectScore[info]["補考"] == "否")
                                {
                                    re = repeatSign;
                                }
                            }

                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs.Add(new Run(e.Document, re));
                            SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs[0].Font.Size = 10;

                            SSTableRowIndex++;
                            if (SSTableRowIndex > SSRowNumber)
                            {
                                SSTableRowIndex  = 1;
                                SSTableColIndex += 4;
                            }
                        }
                    }
                    e.Text = string.Empty;
                }
                catch (Exception ex)
                {
                    SmartSchool.ExceptionHandler.BugReporter.ReportException(ex, true);
                }
            }

            #endregion

            #region 分項成績

            if (e.FieldName == "分項成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <string, Dictionary <string, string> > entryScore = (Dictionary <string, Dictionary <string, string> >)objectValue[0];
                Dictionary <string, string> totalCredit = (Dictionary <string, string>)objectValue[1];
                bool over100 = (bool)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table ESTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int ESRowNumber     = ESTable.Rows.Count - 1;
                int ESTableRowIndex = 1;
                int ESTableColIndex = 0;

                List <string> sortList = new List <string>();
                sortList.AddRange(entryScore.Keys);
                sortList.Sort(SortByEntryName);

                foreach (string entry in sortList)
                {
                    // 先過濾分項原始)
                    if (entry.Contains("(原始)"))
                    {
                        continue;
                    }

                    string semesterDegree = "";
                    if (entry == "德行" || entry == "學年德行成績")
                    {
                        decimal moralScore = decimal.Parse(entryScore[entry]["分數"]);
                        if (!over100 && moralScore > 100)
                        {
                            entryScore[entry]["分數"] = "100";
                        }
                        semesterDegree = " / " + ParseLevel(moralScore);
                    }

                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, ToDisplayName(entry)));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, entryScore[entry]["分數"] + semesterDegree));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                foreach (string key in totalCredit.Keys)
                {
                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, key));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, totalCredit[key]));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 缺曠紀錄

            if (e.FieldName == "缺曠紀錄")
            {
                object[] objectValue = (object[])e.FieldValue;

                if ((Dictionary <string, List <string> >)objectValue[0] == null || ((Dictionary <string, List <string> >)objectValue[0]).Count == 0)
                {
                    e.Text = string.Empty;
                    return;
                }

                Dictionary <string, List <string> > userType    = (Dictionary <string, List <string> >)objectValue[0];
                Dictionary <string, int>            absenceInfo = (Dictionary <string, int>)objectValue[1];

                #region 產生缺曠紀錄表格

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                int    ARowNumber = 3;
                double AWidth     = 0;
                double AHeight    = 0;
                double ARowHeight = 0;

                int    AColumn      = 0;
                double AMicroColumn = 0;

                foreach (string periodType in userType.Keys)
                {
                    AColumn += userType[periodType].Count;
                }

                Cell ACell = (Cell)builder.CurrentParagraph.ParentNode;

                AWidth       = ACell.CellFormat.Width;
                AHeight      = (ACell.ParentNode as Row).RowFormat.Height;
                ARowHeight   = (AHeight) / (ARowNumber);
                AMicroColumn = AWidth / (double)AColumn;

                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.RowFormat.HeightRule            = HeightRule.Exactly;
                builder.RowFormat.Height                = ARowHeight;
                builder.RowFormat.Alignment             = RowAlignment.Center;
                builder.CellFormat.VerticalAlignment    = CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding          = 0.0;
                builder.CellFormat.RightPadding         = 0.0;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                builder.ParagraphFormat.LineSpacing     = 10;
                builder.Font.Size = 10;

                foreach (string periodType in userType.Keys)
                {
                    builder.InsertCell().CellFormat.Width = AMicroColumn * userType[periodType].Count;
                    builder.Write(periodType);
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absence);
                    }
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absenceInfo[periodType + "_" + absence].ToString());
                    }
                }

                builder.EndRow();

                Table ATable = builder.EndTable();

                //去除表格四邊的線
                foreach (Cell cell in ATable.FirstRow.Cells)
                {
                    cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                }

                foreach (Cell cell in ATable.LastRow.Cells)
                {
                    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                }

                foreach (Row row in ATable.Rows)
                {
                    row.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                    row.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                }

                #endregion

                #region 填入缺曠紀錄資料
                #endregion

                e.Text = string.Empty;
            }

            #endregion
        }
コード例 #13
0
        private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 科目成績

            #endregion
        }
コード例 #14
0
        void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "資料")
            {
                int count = 0;
                foreach (StudentInfo stud in StudentInfoDic.Values)
                {
                    foreach (K12.Data.DisciplineRecord record in stud.DISList)
                    {
                        if (record.MeritFlag == "1" && PointMerit)
                        {
                            count++;
                        }
                        else if (record.MeritFlag == "0" && PointDemerit)
                        {
                            if (record.Cleared != "是")
                            {
                                count++;
                            }
                        }
                    }
                }

                Document PageOne = e.Document; // (Document)_template.Clone(true);
                _run = new Run(PageOne);
                DocumentBuilder builder = new DocumentBuilder(PageOne);
                builder.MoveToMergeField("資料");
                ////取得目前Cell
                Cell cell = (Cell)builder.CurrentParagraph.ParentNode;
                ////取得目前Row
                Row row = (Row)builder.CurrentParagraph.ParentNode.ParentNode;

                //建立新行
                for (int x = 1; x < count; x++)
                {
                    (cell.ParentNode.ParentNode as Table).InsertAfter(row.Clone(true), cell.ParentNode);
                }

                foreach (StudentInfo stud in StudentInfoDic.Values)
                {
                    foreach (K12.Data.DisciplineRecord record in stud.DISList)
                    {
                        if (record.MeritFlag == "1" && PointMerit)
                        {
                            #region 獎勵處理

                            List <string> list = new List <string>();
                            list.Add(stud.Class_Nmae);
                            list.Add(stud.Name);
                            list.Add(stud.EngLish_Name);
                            list.Add(record.Reason);
                            list.Add(GetMeMerit(record));

                            foreach (string listEach in list)
                            {
                                Write(cell, listEach);

                                if (cell.NextSibling != null)        //是否最後一格
                                {
                                    cell = cell.NextSibling as Cell; //下一格
                                }
                            }

                            Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一個Row
                            if (Nextrow == null)
                            {
                                break;
                            }
                            cell = Nextrow.FirstCell; //第一格Cell

                            #endregion
                        }
                        else if (record.MeritFlag == "0" && PointDemerit)
                        {
                            #region 懲戒處理
                            if (record.Cleared != "是")
                            {
                                List <string> list = new List <string>();
                                list.Add(stud.Class_Nmae);
                                list.Add(stud.Name);
                                list.Add(stud.EngLish_Name);
                                list.Add(record.Reason);
                                list.Add(GetMeDemerit(record));

                                foreach (string listEach in list)
                                {
                                    Write(cell, listEach);

                                    if (cell.NextSibling != null)        //是否最後一格
                                    {
                                        cell = cell.NextSibling as Cell; //下一格
                                    }
                                }

                                Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一個Row
                                if (Nextrow == null)
                                {
                                    break;
                                }
                                cell = Nextrow.FirstCell; //第一格Cell
                            }

                            #endregion
                        }
                    }
                }
            }
        }
コード例 #15
0
        private void MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            #region 科目成績

            if (e.FieldName == "科目成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> > subjectScore = (Dictionary <SemesterSubjectScoreInfo, Dictionary <string, string> >)objectValue[0];
                string resitSign  = (string)objectValue[1];
                string repeatSign = (string)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table SSTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int SSRowNumber     = SSTable.Rows.Count - 1;
                int SSTableRowIndex = 1;
                int SSTableColIndex = 0;

                List <SemesterSubjectScoreInfo> sortList = new List <SemesterSubjectScoreInfo>();
                sortList.AddRange(subjectScore.Keys);
                sortList.Sort(SortBySemesterSubjectScoreInfo);

                foreach (SemesterSubjectScoreInfo info in sortList)
                {
                    if (SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex] == null)
                    {
                        throw new ArgumentException("科目成績表格不足容下所有科目成績。");
                    }

                    Runs runs = SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex].Paragraphs[0].Runs;
                    runs.Add(new Run(e.Document));
                    runs[runs.Count - 1].Text      = subjectScore[info]["科目"] + ((string.IsNullOrEmpty(subjectScore[info]["級別"])) ? "" : (" (" + subjectScore[info]["級別"] + ")"));
                    runs[runs.Count - 1].Font.Size = 10;
                    runs[runs.Count - 1].Font.Name = "新細明體";

                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["必修"] + subjectScore[info]["學分"]));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs.Add(new Run(e.Document, subjectScore[info]["分數"]));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 2].Paragraphs[0].Runs[0].Font.Size = 10;

                    int    colshift = 0;
                    string re       = "";
                    if (subjectScore[info].ContainsKey("補考"))
                    {
                        if (subjectScore[info]["補考"] == "是")
                        {
                            re = resitSign;
                        }
                        else if (subjectScore[info]["補考"] == "否")
                        {
                            re = repeatSign;
                        }
                    }

                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs.Add(new Run(e.Document, re));
                    SSTable.Rows[SSTableRowIndex].Cells[SSTableColIndex + 3 + colshift].Paragraphs[0].Runs[0].Font.Size = 10;

                    SSTableRowIndex++;
                    if (SSTableRowIndex > SSRowNumber)
                    {
                        SSTableRowIndex  = 1;
                        SSTableColIndex += 4;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 分項成績

            if (e.FieldName == "分項成績起始位置")
            {
                object[] objectValue = (object[])e.FieldValue;
                Dictionary <string, Dictionary <string, string> > entryScore = (Dictionary <string, Dictionary <string, string> >)objectValue[0];
                Dictionary <string, string> totalCredit = (Dictionary <string, string>)objectValue[1];
                bool over100 = (bool)objectValue[2];

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                Table ESTable = ((Row)((Cell)builder.CurrentParagraph.ParentNode).ParentRow).ParentTable;

                int ESRowNumber     = ESTable.Rows.Count - 1;
                int ESTableRowIndex = 1;
                int ESTableColIndex = 0;

                List <string> sortList = new List <string>();
                sortList.AddRange(entryScore.Keys);
                sortList.Sort(SortByEntryName);

                foreach (string entry in sortList)
                {
                    // 先過濾分項原始)
                    if (entry.Contains("(原始)"))
                    {
                        continue;
                    }

                    string semesterDegree = "";
                    if (entry == "德行" || entry == "學年德行成績")
                    {
                        continue;

                        //decimal moralScore = decimal.Parse(entryScore[entry]["分數"]);
                        //if (!over100 && moralScore > 100)
                        //    entryScore[entry]["分數"] = "100";
                        //semesterDegree = " / " + ParseLevel(moralScore);
                    }

                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, ToDisplayName(entry)));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, entryScore[entry]["分數"] + semesterDegree));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                foreach (string key in totalCredit.Keys)
                {
                    Runs runs = ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex].Paragraphs[0].Runs;

                    runs.Add(new Run(e.Document, key));
                    runs[runs.Count - 1].Font.Size = 10;
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs.Add(new Run(e.Document, totalCredit[key]));
                    ESTable.Rows[ESTableRowIndex].Cells[ESTableColIndex + 1].Paragraphs[0].Runs[0].Font.Size = 10;

                    ESTableRowIndex++;
                    if (ESTableRowIndex > ESRowNumber)
                    {
                        ESTableRowIndex  = 1;
                        ESTableColIndex += 2;
                    }
                }

                e.Text = string.Empty;
            }

            #endregion

            #region 缺曠紀錄

            if (e.FieldName == "缺曠紀錄")
            {
                object[] objectValue = (object[])e.FieldValue;

                if ((Dictionary <string, List <string> >)objectValue[0] == null || ((Dictionary <string, List <string> >)objectValue[0]).Count == 0)
                {
                    e.Text = string.Empty;
                    return;
                }

                Dictionary <string, List <string> > userType    = (Dictionary <string, List <string> >)objectValue[0];
                Dictionary <string, int>            absenceInfo = (Dictionary <string, int>)objectValue[1];

                #region 產生缺曠紀錄表格

                DocumentBuilder builder = new DocumentBuilder(e.Document);
                builder.MoveToField(e.Field, false);

                int    ARowNumber = 3;
                double AWidth     = 0;
                double AHeight    = 0;
                double ARowHeight = 0;

                int    AColumn      = 0;
                double AMicroColumn = 0;

                foreach (string periodType in userType.Keys)
                {
                    AColumn += userType[periodType].Count;
                }

                Cell ACell = (Cell)builder.CurrentParagraph.ParentNode;

                AWidth       = ACell.CellFormat.Width;
                AHeight      = (ACell.ParentNode as Row).RowFormat.Height;
                ARowHeight   = (AHeight) / (ARowNumber);
                AMicroColumn = AWidth / (double)AColumn;

                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.RowFormat.HeightRule            = HeightRule.Exactly;
                builder.RowFormat.Height                = ARowHeight;
                builder.RowFormat.Alignment             = RowAlignment.Center;
                builder.CellFormat.VerticalAlignment    = CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding          = 0.0;
                builder.CellFormat.RightPadding         = 0.0;
                builder.ParagraphFormat.Alignment       = ParagraphAlignment.Center;
                builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
                builder.ParagraphFormat.LineSpacing     = 10;
                builder.Font.Size = 10;

                foreach (string periodType in userType.Keys)
                {
                    builder.InsertCell().CellFormat.Width = AMicroColumn * userType[periodType].Count;
                    builder.Write(periodType);
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absence);
                    }
                }

                builder.EndRow();

                foreach (string periodType in userType.Keys)
                {
                    foreach (string absence in userType[periodType])
                    {
                        builder.InsertCell().CellFormat.Width = AMicroColumn;
                        builder.Write(absenceInfo[periodType + "_" + absence].ToString());
                    }
                }

                builder.EndRow();

                Table ATable = builder.EndTable();

                //去除表格四邊的線
                foreach (Cell cell in ATable.FirstRow.Cells)
                {
                    cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                }

                foreach (Cell cell in ATable.LastRow.Cells)
                {
                    cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                }

                foreach (Row row in ATable.Rows)
                {
                    row.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                    row.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                }

                #endregion

                #region 填入缺曠紀錄資料
                #endregion

                e.Text = string.Empty;
            }

            #endregion

            #region 綜合表現(文字評量)

            if (e.FieldName == "綜合表現")
            {
                XmlElement objectValue = (XmlElement)e.FieldValue;

                if (objectValue != null)
                {
                    DocumentBuilder builder = new DocumentBuilder(e.Document);
                    builder.MoveToField(e.Field, false);

                    Cell temp;

                    double width = (builder.CurrentParagraph.ParentNode as Cell).CellFormat.Width;

                    builder.StartTable();
                    //builder.CellFormat.ClearFormatting();
                    foreach (XmlElement each in objectValue.SelectNodes("TextScore/Morality"))
                    {
                        string face = each.GetAttribute("Face");

                        //如果學生身上的face不存在對照表上,就不印出來
                        if ((SmartSchool.Customization.Data.SystemInformation.Fields["文字評量對照表"] as XmlElement).SelectSingleNode("Content/Morality[@Face='" + face + "']") == null)
                        {
                            continue;
                        }

                        string comment = each.InnerText;

                        temp = builder.InsertCell();
                        temp.CellFormat.LeftPadding        = 5;
                        temp.CellFormat.Width              = 120;
                        temp.ParentRow.RowFormat.Alignment = RowAlignment.Left;
                        temp.CellFormat.VerticalAlignment  = CellVerticalAlignment.Center;
                        builder.Write(face);

                        temp = builder.InsertCell();
                        temp.CellFormat.LeftPadding        = 5;
                        temp.CellFormat.Width              = width - 120;
                        temp.ParentRow.RowFormat.Alignment = RowAlignment.Left;
                        temp.CellFormat.VerticalAlignment  = CellVerticalAlignment.Center;
                        builder.Write(comment);
                        builder.EndRow();
                    }
                    Table table = builder.EndTable();

                    if (table.Rows.Count > 0)
                    {
                        foreach (Cell each in table.FirstRow.Cells)
                        {
                            each.CellFormat.Borders.Top.LineStyle = LineStyle.None;
                        }

                        foreach (Cell each in table.LastRow.Cells)
                        {
                            each.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
                        }

                        foreach (Row each in table.Rows)
                        {
                            each.FirstCell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            each.LastCell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                    }

                    e.Field.Remove();
                }
            }
            #endregion
        }