Represents a single row in a Table.
Inheritance: Container
示例#1
0
        private bool isValidHeader(Novacode.Row firstRow)
        {
            bool flag;

            foreach (List <string> list in headers)
            {
                if (list.Count() == firstRow.Cells.Count)
                {
                    flag = true;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (!(list.ElementAt(i).Equals((firstRow.Cells[i].Paragraphs[0].Text).Trim().ToUpper())))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        //This method processes extracts information from a 5 column row
        public void processRowFiveCols(Novacode.Row rowContent)
        {
            string content;
            string contentFirstCell;

            if ((rowContent.Cells.Count == 5) && (foundstone.myTable.isSystem())) //there are some cases in which the tool finds a cell in the middle that has a comment and NOT actual data
            {
                foundstone.writePlatformOrComponentAndKB(rowContent.Cells[0].Paragraphs[0].Text);
                content = foundstone.utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                foundstone.writeComponent(content); // we are doing this because there maybe more than one componenet
            }

            //We are assuming that if it has 5 columns, they must have BKs, and the coponents could be in the 1st column or the 2nd column
            if ((rowContent.Cells.Count == 5) && !(foundstone.myTable.isSystem())) //if it has 5 rows and it is a component, you have to check the where the component is, becouse it could be in the 1st and 2nd column
            {
                if (foundstone.thisCellcontainsConponents(rowContent.Cells[0].Paragraphs[0].Text))
                {
                    content = foundstone.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                    foundstone.writePlatformOrComponentAndKB(content);
                    foundstone.writeComponentsOnly(content); // we are doing this because there maybe more than one componenet        ESTA LINEA LA ESTA CAGANDO
                }
                else
                {
                    content          = foundstone.utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                    contentFirstCell = foundstone.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                    foundstone.writePlatformOrComponentAndKB(content);
                    foundstone.writeComponentsOnly(content, contentFirstCell); // we are doing this because there maybe more than one componenet
                }
            }
        }
示例#3
0
/*WE NEED TO TEST
 * WE NEED TO SAVE THE CONTENT OF A BULLETIN, FROM THE OLD AND THE NEW, SO WE COULD COMPARE THEM
 * WE NEED TO RELEASE THE EXEL SHEET IF A PROBLEM OCCURS*/

        //When the table has 4 columns, it could contain platform or components, that is the reason we have sysorComponent value
        public void processRowFourCols(Novacode.Row rowContent)
        {
            string content, bulletinsRep;

            if (rowContent.Cells.Count == 4)  //there are some cases in which the tool finds a cell in the middle that has a comment and NOT actual data
            {
                scap.writePlatformOrComponentAndKB(rowContent.Cells[0].Paragraphs[0].Text, rowContent.Cells[3].Paragraphs[0].Text);
                scap.sheet.Cells[scap.getRow(), scap.getCdAt("risk")] = rowContent.Cells[2].Paragraphs[0].Text;
                content      = scap.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                bulletinsRep = scap.utilities.getTextFromCell(rowContent.Cells[3].Paragraphs);
                if (scap.myTable.isSystem())
                {
                    scap.writeSystem(content, bulletinsRep); // we are doing this because there maybe more than one componenet
                }
                else
                {
                    scap.writeComponent(content, bulletinsRep);
                }
            }

            if (rowContent.Cells.Count == 1)
            {
                content = rowContent.Cells[0].Paragraphs[0].Text;
                scap.myTable.setSupportedHeader(content);
                //myTable.setSystemOrComponent(content);
            }
        }
示例#4
0
        public bool tableContainsCVEs(Novacode.Row row)
        {
            string tableHeaderContainCVE = "VULNERABILITY SEVERITY RATING AND MAXIMUM SECURITY IMPACT BY AFFECTED SOFTWARE";

            if ((row.Cells.Count == 1) && (tableHeaderContainCVE.Equals(row.Cells[0].Paragraphs[0].Text.ToUpper().Trim())))
            {
                return(true);
            }
            return(false);
        }
示例#5
0
 //Given a row with columns, verify whether that row defines a table with affected software.
 public bool containsAffectedSoftware(Novacode.Row firstRow)
 {
     if ((firstRow.Cells.Count == 4) || (firstRow.Cells.Count == 5))
     {
         if (isValidHeader(firstRow))
         {
             return(true);
         }
     }
     return(false);
 }
示例#6
0
 private bool equalToHeader(Novacode.Row row, string[] validHeader)
 {
     for (int i = 1; i < 4; i++)
     {
         //                System.Windows.Forms.MessageBox.Show("comparando:" + validHeader[i] + ";" + row.Cells[i].Paragraphs[0].Text);
         if (!(validHeader[validHeader.Length - i].Equals(((row.Cells[row.Cells.Count - i].Paragraphs[0].Text).Trim()).ToUpper())))
         {
             return(false);
         }
     }
     return(true);
 }
示例#7
0
        private void ExportWordTable()
        {
            List <SINHVIENEntities> lstSINHVIEN = dapSINHVIEN.GetAll();

            if (lstSINHVIEN != null)
            {
                //Khai báo đường dẫn của file sau khi lưu
                string urlFileSave = "/AppFile/tmp/ListSV.docx";
                urlFileSave = Server.MapPath(urlFileSave);
                //Khai báo đường dẫn của file doc được đọc
                string fileName = Server.MapPath("/AppFile/Docs/ExportWordTable.docx");

                using (DocX doc = DocX.Load(fileName))
                {
                    Novacode.Table tblSINHVIEN = doc.Tables[1];
                    Novacode.Row   rowCn       = tblSINHVIEN.Rows[1];
                    int            count       = 2;
                    Novacode.Row   newRow;

                    for (int i = 0; i < lstSINHVIEN.Count; i++)
                    {
                        newRow = tblSINHVIEN.InsertRow(rowCn, count++);
                        newRow.Cells[0].ReplaceText("@stt", (i + 1).ToString());
                        newRow.Cells[1].ReplaceText("@hovaten", lstSINHVIEN[i].HOVATEN == null ? "" : lstSINHVIEN[i].HOVATEN);
                        newRow.Cells[2].ReplaceText("@ngaysinh", lstSINHVIEN[i].NGAYSINH == null ? "" : lstSINHVIEN[i].NGAYSINH.ToString("dd/MM/yyyy"));
                        newRow.Cells[3].ReplaceText("@gioitinh", lstSINHVIEN[i].GIOITINH == 1 ? "Nam" : "Nữ");
                        newRow.Cells[4].ReplaceText("@diachi", lstSINHVIEN[i].DIACHI == null ? "" : lstSINHVIEN[i].DIACHI);
                        newRow.Cells[5].ReplaceText("@sdt", lstSINHVIEN[i].SDT == null ? "" : lstSINHVIEN[i].SDT);
                        newRow.Cells[6].ReplaceText("@email", lstSINHVIEN[i].EMAIL == null ? "" : lstSINHVIEN[i].EMAIL);
                        newRow.Cells[7].ReplaceText("@lop", lstSINHVIEN[i].TENLOP);
                    }
                    tblSINHVIEN.RemoveRow(1);
                    doc.SaveAs(urlFileSave);
                    doc.Save();
                    Response.Buffer  = true;
                    Response.Expires = 0;
                    Response.Clear();
                    string strHttpContext_ContentType = "application/msword";
                    HttpContext.Current.Response.ContentType     = strHttpContext_ContentType;
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.Charset         = "utf-8";
                    Response.AddHeader("Content-Disposition", "attachment; filename=BangThongTinSinhVien" + ".docx");
                    Response.TransmitFile(urlFileSave);
                    Response.Flush();
                    Response.Close();
                    Response.End();
                }
            }
        }
示例#8
0
        private string concatCVEs(Novacode.Row row)
        {
            string result = "";

            for (int i = 0; i < row.Cells.Count; i++)
            {
                //TODO maybe there are more than on paragraph
                Paragraph paragrap = row.Cells[i].Paragraphs[0];
                if (paragrap.Text.Contains("CVE-"))
                {
                    result += getCVEfromString(paragrap.Text) + " ";
                }
            }
            return(result);
        }
示例#9
0
        //This method processes extracts information from a 5 column row
        public void processRowFiveCols(Novacode.Row rowContent)
        {
            string content, bulletinsRep, contentFirstCell;

            if ((rowContent.Cells.Count == 5) && (scap.myTable.isSystem())) //there are some cases in which the tool finds a cell in the middle that has a comment and NOT actual data
            {
                scap.writePlatformOrComponentAndKB(rowContent.Cells[0].Paragraphs[0].Text, rowContent.Cells[4].Paragraphs[0].Text);
                scap.sheet.Cells[scap.getRow(), scap.getCdAt("risk")] = rowContent.Cells[3].Paragraphs[0].Text;
                content      = scap.utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                bulletinsRep = scap.utilities.getTextFromCell(rowContent.Cells[4].Paragraphs);
                scap.writeComponent(content, bulletinsRep); // we are doing this because there maybe more than one componenet
            }

            //We are assuming that if it has 5 columns, they must have KBs, and the coponents could be in the 1st column or the 2nd column
            else
            {
                if ((rowContent.Cells.Count == 5) && (scap.myTable.isComponent())) //if it has 5 rows and it is a component, you have to check the where the component is, becouse it could be in the 1st and 2nd column
                {
                    content      = scap.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                    bulletinsRep = scap.utilities.getTextFromCell(rowContent.Cells[4].Paragraphs);

                    if (scap.utilities.thisCellcontainsConponents(content))  //Is the information we are interested in at Colum 0?
                    {
                        scap.writePlatformOrComponentAndKB(content, bulletinsRep);
                        scap.sheet.Cells[scap.getRow(), scap.getCdAt("risk")] = rowContent.Cells[3].Paragraphs[0].Text;
                        scap.writeComponentsOnly(content, bulletinsRep); // we are doing this because there maybe more than one component
                    }
                    else
                    {
                        content          = scap.utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                        contentFirstCell = scap.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                        //comments = utilities.extractSigns(utilities.getTextFromCell(rowContent.Cells[0].Paragraphs)); //This is because maybe the comments are in the other column

                        scap.writePlatformOrComponentAndKB(content, bulletinsRep);
                        scap.sheet.Cells[scap.getRow(), scap.getCdAt("risk")] = rowContent.Cells[3].Paragraphs[0].Text;
                        scap.writeComponentsOnly(content, bulletinsRep, contentFirstCell); // we are doing this because there maybe more than one componenet
                    }
                }

                if (rowContent.Cells.Count == 1)    //there is a row with only one column, so we must to check whether is a CORE install
                {
                    content = rowContent.Cells[0].Paragraphs[0].Text;
                    scap.myTable.setSupportedHeader(content);
                    //myTable.setSystemOrComponent(content);
                }
            }
        }
示例#10
0
        //When the table has 4 columns, it could contain platform or components, that is the reason we have sysorComponent value
        public void processRowFourCols(Novacode.Row rowContent)
        {
            string content;

            if (rowContent.Cells.Count == 4)  //there are some cases in which the tool finds a cell in the middle that has a comment and NOT actual data
            {
                foundstone.writePlatformOrComponentAndKB(rowContent.Cells[0].Paragraphs[0].Text);
                content = foundstone.utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                if (foundstone.myTable.isSystem())
                {
                    foundstone.writeSystem(content); // we are doing this because there maybe more than one componenet
                }
                else
                {
                    foundstone.writeComponent(content); // we are doing this because there maybe more than one componenet
                }
            }
        }
示例#11
0
        //This method processes extracts information from a 5 column row
        public void processRowFiveCols(Novacode.Row rowContent)
        {
            string content, contentFirstCell;

            if ((rowContent.Cells.Count == 5) && (myTable.isSystem())) //there are some cases in which the tool finds a cell in the middle that has a comment and NOT actual data
            {
                //content = utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                writePlatformOrComponentAndKB(rowContent.Cells[0].Paragraphs[0].Text);
                sheet.Cells[row, cd["risk"]] = rowContent.Cells[3].Paragraphs[0].Text;
                content = utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                writeComponent(content); // we are doing this because there maybe more than one componenet
            }

            //We know it has 5 columns, they must have BKs, and the coponents could be in the 1st column or the 2nd column
            else
            if ((rowContent.Cells.Count == 5) && !(myTable.isSystem()))     //if it has 5 rows and it is a component, you have to check the where the component is, becouse it could be in the 1st and 2nd column
            {
                content = utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);

                if (utilities.thisCellcontainsConponents(content))
                {
                    writePlatformOrComponentAndKB(content);
                    sheet.Cells[row, cd["risk"]] = rowContent.Cells[3].Paragraphs[0].Text;
                    writeComponentsOnly(content);         // we are doing this because there maybe more than one component
                }
                else
                {
                    content          = utilities.getTextFromCell(rowContent.Cells[1].Paragraphs);
                    contentFirstCell = utilities.getTextFromCell(rowContent.Cells[0].Paragraphs);
                    //comments = utilities.extractSigns(utilities.getTextFromCell(rowContent.Cells[0].Paragraphs)); //This is because maybe the comments are in the other column

                    writePlatformOrComponentAndKB(content);
                    sheet.Cells[row, cd["risk"]] = rowContent.Cells[3].Paragraphs[0].Text;
                    writeComponentsOnly(content, contentFirstCell);         // we are doing this because there maybe more than one componenet
                }
            }
        }
        private int FillCell(Novacode.Row rr, int col, ExcelPic p)
        {
            var c   = rr.Cells[col];
            var img = ImageData.Image.ImageFromId(p.ImageId);

            if (img != null)
            {
                using (var os = img.ResizeToStream(200, 300, "max"))
                {
                    var pic = dd.AddImage(os).CreatePicture((pa.PicWidthPixels * 1.5).ToInt(), pa.PicWidthPixels);
                    c.Paragraphs[0].InsertPicture(pic);
                }
            }
            col++;
            c = rr.Cells[col];
            //c.RemoveParagraphAt(0);

            c.Paragraphs[0].InsertText("{0}, {1}".Fmt(p.LastName, p.FirstName), false, pa.namebold);

            c.InsertParagraph(p.Email, false, pa.emailsmall);

            if (p.BirthDate.HasValue())
            {
                c.InsertParagraph("BD {0}".Fmt(p.BirthDay), false, pa.font);
            }
            if (p.Spouse.HasValue())
            {
                c.InsertParagraph("Spouse: {0}".Fmt(p.Spouse), false, pa.font);
            }
            if (p.Children.HasValue())
            {
                c.InsertParagraph("Kids: {0}".Fmt(p.Children), false, pa.font);
            }
            col++;
            return(col);
        }
示例#13
0
文件: Table.cs 项目: WordDocX/DocX
        private Row InsertRow(List<XElement> content, Int32 index)
        {
            Row newRow = new Row(this, Document, new XElement(XName.Get("tr", DocX.w.NamespaceName), content));

            XElement rowXml;
            if (index == Rows.Count)
            {
                rowXml = Rows.Last().Xml;
                rowXml.AddAfterSelf(newRow.Xml);
            }

            else
            {
                rowXml = Rows[index].Xml;
                rowXml.AddBeforeSelf(newRow.Xml);
            }

            return newRow;
        }
示例#14
0
        /// <summary>
        /// <para>Проверяет данные заявки</para>
        /// <para>Возвращает true если данные разобраны без ошибок и false в противном случае.</para>
        /// </summary>
        /// <param name="row">Строка таблицы.</param>
        /// <param name="parsedData">out ArayList с данными либо с ошибками, если разбор завершился неудаче.</param>
        bool CheckAppeal(Row row, ArrayList appeals, out ArrayList errors)
        {
            errors = new ArrayList();
            bool result = true;
            string cellText = "";
            string tmp;
            string DeclarantType = "";
            string DeclarantParty = "";
            ArrayList cellParsedValues;
            ArrayList Subjects = new ArrayList();
            ArrayList NumbersAndDates = new ArrayList();
            // ФИО и info заявителей из колонки "Кем заявлено".
            ArrayList AppealDeclarants = new ArrayList();
            // Объект для хранения общих данных обращения/обращений
            Appeal NewAppeal = new Appeal();
            NewAppeal.init();
            // Пропускаем первую и последнюю колонку.
            for (int colIndex = 1; colIndex < row.Cells.Count - 1; colIndex++) {
                Cell c = row.Cells[colIndex];
                cellText = "";
                tmp = "";
                // Собираем текст ячейки из всех параграфов в одну переменную.
                for (int i = 0; i < c.Paragraphs.Count; i++) {
                    if (c.Paragraphs[i].Text.Trim() != "") {
                        cellText += c.Paragraphs[i].Text + " ";
                    }
                }
                // Запускаем разбор текста из ячейки.
                switch (colIndex) {
                    // Субъект РФ+
                    case 1:
                        if (ParseSubject(cellText, out cellParsedValues)) {
                            // Проверка завершилась успешно - заполняем массив субъектов
                            foreach (string str in cellParsedValues) {
                                Subjects.Add(str);
                            }
                        } else {
                            // Проверка завершилась с ошибкой.
                            result = false;
                            errors.Add(new ErrorMessage("Субъект Российской Федерации: ", MessageType.Header, colIndex));
                            // Добавляем все сообщения об ошибках в errors.
                            foreach (string str in cellParsedValues) {
                                errors.Add(new ErrorMessage(str, MessageType.Text));
                            }
                        }
                        break;
                    // Содержание+
                    case 2:
                        if (ParseContent(cellText, out tmp)) {
                            NewAppeal.content = tmp;
                        } else {
                            result = false;
                            errors.Add(new ErrorMessage("Содержание: ", MessageType.Header, colIndex));
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }
                        break;
                    // Заявитель+
                    case 3:
                        if (ParseDeclarant(cellText, out cellParsedValues)) {
                            // Проверка завершилась успешно - заполняем массив заявителей
                            foreach (string[] str in cellParsedValues) {
                                AppealDeclarants.Add(str);
                            }

                        } else {
                            // Проверка завершилась с ошибкой.
                            result = false;
                            errors.Add(new ErrorMessage("Кем заявлено: ", MessageType.Header, colIndex));

                            // Добавляем все сообщения об ошибках в errors.
                            foreach (string[] str in cellParsedValues) {
                                errors.Add(new ErrorMessage(str[0],MessageType.Text));
                            }
                        }
                        break;
                    // Сведения о подтверждении
                    case 4:
                        if (ParseConfirmation(cellText, out tmp)) {
                            NewAppeal.confirmation = tmp;
                        } else {
                            result = false;
                            errors.Add(new ErrorMessage("Сведения о подтверждении: ", MessageType.Header, colIndex));
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }
                        break;
                    // Приянтые меры
                    case 5:
                        if (ParseMeasures(cellText, out tmp)) {
                            NewAppeal.measures = tmp;
                        } else {
                            result = false;
                            errors.Add(new ErrorMessage("Приянтые меры: ", MessageType.Header, colIndex));
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }
                        break;
                    // Номер и дата
                    case 6:
                        if (ParseNumberAndDate(cellText, out cellParsedValues)) {
                            // Проверка завершилась успешно - заполняем массив субъектов
                            foreach (Tuple<string, string> NumDate in cellParsedValues) {
                                NumbersAndDates.Add(NumDate);
                            }
                        } else {
                            // Проверка завершилась с ошибкой.
                            result = false;
                            errors.Add(new ErrorMessage("Рег. номер и дата: ", MessageType.Header, colIndex));
                            // Добавляем все сообщения об ошибках в errors.
                            foreach (string str in cellParsedValues) {
                                errors.Add(new ErrorMessage(str, MessageType.Text));
                            }
                        }
                        break;
                    // 7 - Уровень выборов
                    // Партия
                    case 8:
                        if (ParseParty(cellText, out tmp)) {
                            DeclarantParty = tmp;
                            //NewAppeal.multi.Add(new string[] { "tematika", tmp });
                        } else {
                            // Проверка завершилась с ошибкой.
                            result = false;
                            errors.Add(new ErrorMessage("Партия: ", MessageType.Header, colIndex));
                            // Добавляем все сообщения об ошибках в errors.
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }

                        break;
                    // Тип заявителя
                    case 9:
                        if (ParseDeclarantType(cellText, out tmp)) {
                            //NewAppeal.declarant_type = tmp;
                            DeclarantType = tmp;
                        } else {
                            result = false;
                            errors.Add(new ErrorMessage("Тип заявителя: ", MessageType.Header, colIndex));
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }

                        break;
                    // Тематика
                    case 10:
                        if (ParseTheme(cellText, out cellParsedValues)) {
                            int ThemeIndex = 0;
                            foreach(string str in cellParsedValues) {
                                NewAppeal.multi.Add(new string[] { "tematika", str, ThemeIndex.ToString() });
                                ThemeIndex++;
                            }
                        } else {
                            // Проверка завершилась с ошибкой.
                            result = false;
                            errors.Add(new ErrorMessage("Тематика: ", MessageType.Header, colIndex));

                            // Добавляем все сообщения об ошибках в errors.
                            foreach (string str in cellParsedValues) {
                                errors.Add(new ErrorMessage(str, MessageType.Text));
                            }
                        }
                        break;
                    // 11 - +
                    // Исполнитель
                    case 12:
                        if (ParseExecutor(cellText, out tmp)) {
                            NewAppeal.executor_id = tmp;
                        } else {
                            result = false;
                            errors.Add(new ErrorMessage("Исполнитель: ", MessageType.Header, colIndex));
                            errors.Add(new ErrorMessage(tmp, MessageType.Text));
                        }
                        break;
                }
            }

            // Проверяем заявителей
            bool NewDeclarant;
            string DeclarantID = "";
            int DeclarantIndex = 0;
            foreach (string[] fio_info in AppealDeclarants) {
                NewDeclarant = true;
                Declarant d = new Declarant(DeclarantType, DeclarantParty, fio_info[1]);
                d.SetFIO(fio_info[0]);
                // Ищем в справочнике.
                foreach (Declarant dd in Declarants) {
                    if (d.Equals(dd)) {
                        NewDeclarant = false;
                        DeclarantID = dd.GetID();
                        break;
                    }
                }
                if (NewDeclarant) {
                    // Добавляем в справочник заявителя с фиктивным ID.
                    DeclarantID = "fake-" + this.DeclarantFakeID++;
                    if (d.SetID(DeclarantID)) {
                        Declarants.Add(d);
                    }
                }
                // Проверяем, что такого заявителя ещё нет в данной заявке.
                NewDeclarant = true;
                foreach (string[] str in NewAppeal.multi) {
                    if (str[0] == "declarant" && str[1] == DeclarantID) {
                        NewDeclarant = false;
                        break;
                    }
                }

                if (NewDeclarant) {
                    // Добавляем заявителя к обращению.
                    NewAppeal.multi.Add(new string[] { "declarant", DeclarantID, DeclarantIndex.ToString() });
                    DeclarantIndex++;
                }
            }
            // Добавляем субъекты
            int SubjCodeIndex = 0;
            foreach (string sc in Subjects) {
                NewAppeal.multi.Add(new string[] { "ik_subjcode", sc, SubjCodeIndex.ToString() });
                SubjCodeIndex++;
            }

            // Создаём "простые" обращения
            foreach (Tuple<string, string> NumDate in NumbersAndDates) {
                string ParentID = null;
                if(Subjects.Count > 1) {
                    // Указано несколько субъектов - создаём родительской обращение
                    ParentID = this.AppealFakeID.ToString();
                    this.AppealFakeID++;
                    ParentID = "999" + ParentID.PadLeft(5, '0');
                    NewAppeal.Prepare(ParentID, null, "0", NumDate.Item1, NumDate.Item2);
                    appeals.Add(NewAppeal);
                } else {
                    ParentID = null;
                }
                foreach (string SubjCode in Subjects) {
                    NewAppeal.Prepare(null, ParentID, SubjCode, NumDate.Item1, NumDate.Item2);
                    appeals.Add(NewAppeal);
                }
            }
            return result;
        }
示例#15
0
文件: Table.cs 项目: WordDocX/DocX
        /// <summary>
        /// Insert a copy of a row into this table.
        /// </summary>
        /// <param name="row">Row to copy and insert.</param>
        /// <param name="index">Index to insert row at.</param>
        /// <returns>A new Row</returns>
        public Row InsertRow(Row row, int index)
        {
            if (row == null)
                throw new ArgumentNullException(nameof(row));

            if (index < 0 || index > RowCount)
                throw new IndexOutOfRangeException();

            List<XElement> content = row.Xml.Elements(XName.Get("tc", DocX.w.NamespaceName)).Select(element => HelperFunctions.CloneElement(element)).ToList();
            return InsertRow(content, index);
        }
示例#16
0
文件: Table.cs 项目: WordDocX/DocX
 /// <summary>
 /// Adds a cell to the right or left of a cell
 /// </summary>
 /// <param name="row">is the row you are adding</param>
 /// <param name="cell">is the cell you are adding</param>
 /// <param name="index">the cell index position you are refferencing from</param>
 /// <param name="direction">which side of the cell you wish to add cell</param>
 private void AddCellToRow(Row row, XElement cell, int index, bool direction)
 {
     index -= 1;
     if (direction)
     {
         row.Cells[index].Xml.AddAfterSelf(cell);
     }
     else
     {
         row.Cells[index].Xml.AddBeforeSelf(cell);
     }
 }
示例#17
0
文件: Table.cs 项目: WordDocX/DocX
 internal Cell(Row row, DocX document, XElement xml)
     : base(document, xml)
 {
     this.row = row;
     this.mainPart = row.mainPart;
 }
示例#18
0
文件: Table.cs 项目: WordDocX/DocX
 /// <summary>
 /// Insert a copy of a row at the end of this table.
 /// </summary>      
 /// <returns>A new row.</returns>
 public Row InsertRow(Row row)
 {
     return InsertRow(row, RowCount);
 }
示例#19
0
 internal void Tr()
 {
     while (tbly >= tbl.RowCount) tbl.InsertRow();
     tr = tbl.Rows[tbly];
     tblx = 0;
     tbly++;
 }
 private void SetBorder(Row row)
 {
     foreach (var cell in row.Cells)
     {
         SetBorder(cell);
     }
 }
示例#21
0
 private void ExportWord()
 {
     if (Tables != null)
     {
         var columns = Columns;
         using (Docx.DocX doc = Docx.DocX.Create(FileName))
         {
             //表格的边框样式
             Docx.Border border = new Docx.Border();
             border.Tcbs = Docx.BorderStyle.Tcbs_single;
             int n = 0;
             foreach (TableEntity tableEntity in Tables)
             {
                 string tableId = tableEntity.ID.ToString();
                 //插入表名
                 Docx.Paragraph title = doc.InsertParagraph();
                 title.Append(tableEntity.TableName + "(" + tableEntity.Attr + ")");
                 title.Alignment = Docx.Alignment.center;
                 title.FontSize(15);
                 title.Bold();
                 title.SetLineSpacing(Docx.LineSpacingType.After, 1);
                 title.SetLineSpacing(Docx.LineSpacingType.Before, 1);
                 DataTable fields   = service.GetColumnDataTable(tableId);
                 int       rowCount = (fields == null ? 0 : fields.Rows.Count) + 1;
                 //计算表格多少行,多少列
                 Docx.Table table = doc.InsertTable(rowCount, columns.Count);
                 //先生成列头
                 Docx.Row colRow = table.Rows[0];
                 int      k      = 0;
                 foreach (string colKey in columns.Keys)
                 {
                     Docx.Cell colCell = colRow.Cells[k];
                     colCell.Paragraphs[0].Append(columns[colKey]).Alignment = Docx.Alignment.center;
                     colCell.SetBorder(Docx.TableCellBorderType.Top, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Bottom, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Left, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Right, border);
                     k++;
                 }
                 for (int i = 0; i < fields.Rows.Count; i++)
                 {
                     //一个属性为一行
                     Docx.Row row = table.Rows[i + 1];
                     //循环每列
                     int j = 0;
                     foreach (string key in columns.Keys)
                     {
                         Docx.Cell cell = row.Cells[j];
                         string    text = fields.Rows[i][key].ToString();
                         if (key == requiredKey)
                         {
                             text = text.ToLower() == "true" ? "是" : "";
                         }
                         cell.Paragraphs[0].Append(text).Alignment = Docx.Alignment.center;
                         cell.Paragraphs[0].FontSize(10);
                         cell.SetBorder(Docx.TableCellBorderType.Top, border);
                         cell.SetBorder(Docx.TableCellBorderType.Bottom, border);
                         cell.SetBorder(Docx.TableCellBorderType.Left, border);
                         cell.SetBorder(Docx.TableCellBorderType.Right, border);
                         j++;
                     }
                 }
                 n++;
                 if (OnProgress != null)
                 {
                     OnProgress(this, new ProgressEventArgs()
                     {
                         Max = Tables.Count, Value = n
                     });
                 }
             }
             doc.Save();
         }
     }
 }
示例#22
0
文件: Table.cs 项目: JonKruger/DocX
        /// <summary>
        /// Insert a row into this table.
        /// </summary>
        /// <example>
        /// <code>
        /// // Load a document.
        /// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
        /// {
        ///     // Get the first table in this document.
        ///     Table table = document.Tables[0];
        ///        
        ///     // Insert a new row at index 1 in this table.
        ///     Row row = table.InsertRow(1);
        ///
        ///     // Loop through each cell in this new row.
        ///     foreach (Cell c in row.Cells)
        ///     {
        ///         // Set the text of each new cell to "Hello".
        ///         c.Paragraph.InsertText("Hello", false);
        ///     }
        ///
        ///     // Save the document to a new file.
        ///     document.SaveAs(@"C:\Example\Test2.docx");
        /// }// Release this document from memory.
        /// </code>
        /// </example>
        /// <param name="index">Index to insert row at.</param>
        /// <returns>A new Row</returns>
        public Row InsertRow(int index)
        {
            if (index < 0 || index > rows.Count)
                throw new IndexOutOfRangeException();

            List<XElement> content = new List<XElement>();

            foreach (Cell c in rows[0].Cells)
                content.Add(new XElement(XName.Get("tc", DocX.w.NamespaceName), new XElement(XName.Get("p", DocX.w.NamespaceName))));

            XElement e = new XElement(XName.Get("tr", DocX.w.NamespaceName), content);
            Row newRow = new Row(document, e);

            XElement rowXml;
            if (index == rows.Count)
            {
                rowXml = rows.Last().xml;
                rowXml.AddAfterSelf(newRow.xml);
            }

            else
            {
                rowXml = rows[index].xml;
                rowXml.AddBeforeSelf(newRow.xml);
            }

            rows.Insert(index, newRow);
            rowCount = rows.Count;
            return newRow;
        }
示例#23
0
        private void AddFamily(Row rr, FamilyInfo f)
        {
            var c = rr.Cells[0];
            var img = ImageData.Image.ImageFromId(f.ImageId);
            if (img != null)
            {
                var ratio = img.Ratio();
                using (var os = img.ResizeToStream("width=1000&height=1000&mode=max"))
                {
                    var h = pa.PicHeightPixels;
                    var w = h * ratio;

                    var str = dd.AddImage(os);
                    var pic = str.CreatePicture(h.ToInt(), w.ToInt());

                    c.Paragraphs[0].InsertPicture(pic);
                    c.Paragraphs[0].Alignment = Alignment.center;
                }
            }

            c.InsertParagraph();
            var p = c.InsertParagraph(f.Title, false, pa.namebold);
            p.Alignment = Alignment.center;

            var cc = f.Children().ToList();

            c.InsertParagraph("", false, pa.font);
            var t2 = c.InsertTable(cc.Count + 2 + (f.Head2.HasValue() ? 1 : 0), 2);
            t2.Alignment = Alignment.center;
            t2.AutoFit = AutoFit.Contents;
            t2.Rows[0].Cells[1].Width = 0;

            var row = 0;
            t2.Rows[row].Cells[0].Paragraphs[0].InsertText(f.Head1, false, pa.font);
            t2.Rows[row].Cells[1].Paragraphs[0].InsertText(f.BirthDay, false, pa.font);
            if (f.Head2 != null)
            {
                row++;
                t2.Rows[0].Cells[1].Width = 0;
                t2.Rows[row].Cells[0].Paragraphs[0].InsertText(f.Head2, false, pa.font);
                t2.Rows[row].Cells[1].Paragraphs[0].InsertText(f.BirthDay2, false, pa.font);
            }
            foreach (var ch in cc)
            {
                row++;
                t2.Rows[0].Cells[1].Width = 0;
                t2.Rows[row].Cells[0].Paragraphs[0].InsertText(ch.Display, false, pa.font);
                t2.Rows[row].Cells[1].Paragraphs[0].InsertText(ch.BirthDay, false, pa.font);
            }
            row++;
            t2.Rows[row].MergeCells(0, 1);

            var cell = t2.Rows[row].Cells[0];
            var pg = cell.Paragraphs[0];

            var addr = f.FullAddress;
            if (addr.HasValue())
                pg.InsertText("\n" + addr, false, pa.font);

            var phones = f.Phones;
            if(phones.HasValue())
                pg.InsertText("\n" + phones, false, pa.font);

            var emails = f.Emails;
            if(emails.HasValue())
                pg.InsertText("\n" + emails, false, pa.font);
        }
示例#24
0
        /// <summary>
        /// 获取表中的列信息
        /// </summary>
        /// <param name="row">行节点</param>
        /// <param name="dic">列名字典集合</param>
        /// <param name="pTable">表信息</param>
        private void InitColumns(Row row, Dictionary<int, string> dic, TableInfo pTable)
        {
            ColumnInfo mColumn = new ColumnInfo();
            int iCell = 0;
            //列ID
            mColumn.ColumnObjectId = Guid.NewGuid().ToString();
            string sTemp="";
            foreach (var cell in row.Cells)
            {
                sTemp=cell.Paragraphs[0].Text.Trim();
                Common.GetColumnInfo(dic, sTemp, mColumn, iCell, pTable);
                iCell++;
            }
            //2014-07-28 添加错误详细信息提示,以便准确知道错误地方
            Common.JudgeColumnInfo(mColumn, pTable.Code);
            mColumn.DataTypeStr=Common.GetDataTypeStr(mColumn.DataTypeStr, mColumn.Width);
            mColumn.Width = Common.GetColumnWidth(mColumn.DataTypeStr);

            //杜冬军2014-07-23修改,添加主键列的判定方式 ,如果中文名称类似 A(主键) 则认为该列是主键列
            Common.GetPrimaryKeyInfo(mColumn, pTable);

            if (string.IsNullOrEmpty(mColumn.Comment))
            {
                mColumn.Comment = mColumn.Name;
            }
            if (string.IsNullOrEmpty(mColumn.DefaultValue))
            {
                mColumn.DefaultValue = "";
            }
            mColumn.Sequence = pTable.ListColumnInfo.Count + 1;
            pTable.ListColumnInfo.Add(mColumn);
        }
示例#25
0
        /// <summary>
        /// 获取表中的列信息
        /// </summary>
        /// <param name="row">行节点</param>
        /// <param name="dic">列名字典集合</param>
        /// <param name="pTable">表信息</param>
        private void InitColumns(Row row, Dictionary<int, string> dic, TableInfo pTable)
        {
            ColumnInfo mColumn = new ColumnInfo();
            int iCell = 0;
            //列ID
            mColumn.ColumnObjectId = Guid.NewGuid().ToString();
            string sTemp="";
            foreach (var cell in row.Cells)
            {
                sTemp=cell.Paragraphs[0].Text.Trim();
                Common.GetColumnInfo(dic, sTemp, mColumn, iCell, pTable);
                iCell++;
            }
            mColumn.DataTypeStr=Common.GetDataTypeStr(mColumn.DataTypeStr, mColumn.Width);
            mColumn.Width = Common.GetColumnWidth(mColumn.DataTypeStr);

            if (string.IsNullOrEmpty(mColumn.Comment))
            {
                mColumn.Comment = mColumn.Name;
            }
            if (string.IsNullOrEmpty(mColumn.DefaultValue))
            {
                mColumn.DefaultValue = "";
            }
            mColumn.Sequence = pTable.ListColumnInfo.Count + 1;
            pTable.ListColumnInfo.Add(mColumn);
        }