Esempio n. 1
0
        private void AddRowWithReplacements(Xceed.Words.NET.Table tbl, RollsheetPersonInfo m, int orgId)
        {
            var row = tbl.InsertRow(docx.Tables[0].Rows[0]);

            tbl.Rows.Add(row);
            var dict = replacements.DocXReplacementsDictionary(m.Person, orgId);

            foreach (var p in row.Paragraphs.Where(vv => vv.Text.HasValue()))
            {
                if (dict.Keys.Any(vv => p.Text.Contains(vv)))
                {
                    foreach (var d in dict)
                    {
                        if (p.Text.Contains(d.Key))
                        {
                            if (d.Key == "{barcodepeopleid}")
                            {
                                var s   = BarCodeStream(m.Person.PeopleId.ToString(), 40, showtext: false);
                                var img = curr.AddImage(s);
                                p.AppendPicture(img.CreatePicture());
                                p.ReplaceText(d.Key, "");
                            }
                            else if (d.Key.Equal("{MLG}"))
                            {
                                p.ReplaceText(d.Key, m.MemberTypeCode);
                            }
                            else if (d.Key.Equal("{highlight}"))
                            {
                                if (m.Highlight.HasValue())
                                {
                                    p.ReplaceText(d.Key, m.Highlight);
                                }
                                else
                                {
                                    p.Remove(false);
                                }
                            }
                            else if (d.Key.Equal("{altname}"))
                            {
                                p.ReplaceText(d.Key, m.UseAltName ? m.Person.AltName : "");
                            }
                            else if (d.Key.Equal("{name}"))
                            {
                                p.ReplaceText(d.Key, m.Person.Name2);
                                if (m.MemberTypeCode == "VS")
                                {
                                    row.Cells.Last().Shading = Color.FromArgb(226, 239, 217); // light green
                                }
                            }
                            else
                            {
                                p.ReplaceText(d.Key, d.Value);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        void MergeCell(Xceed.Words.NET.Table docxTable)
        {
            int rowCount    = docxTable.RowCount;
            int columnCount = docxTable.ColumnCount;

            #region 处理跨行
            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    //Console.WriteLine("i:" + i + ",j:" + j);
                    var ps = docxTable.Rows[i].Cells[j].Paragraphs;
                    if (ps == null || ps.Count < 1)
                    {
                        continue;
                    }

                    string text = docxTable.Rows[i].Cells[j].Paragraphs[0].Text;
                    if (docxTable.Rows[i].Cells[j].Paragraphs[0].Text == "|" && i > 0)
                    {
                        docxTable.MergeCellsInColumn(j, i - 1, i);
                    }
                }
            }
            #endregion

            #region 处理跨列
            for (int i = 0; i < rowCount; i++)
            {
                int colnum = columnCount;
                for (int j = 0; j < colnum;)
                {
                    //Console.WriteLine("i:" + i + ",j:" + j);
                    var ps = docxTable.Rows[i].Cells[j].Paragraphs;
                    if (ps == null || ps.Count < 1)
                    {
                        continue;
                    }

                    string text = docxTable.Rows[i].Cells[j].Paragraphs[0].Text;
                    if (docxTable.Rows[i].Cells[j].Paragraphs[0].Text == "||" && j > 0)
                    {
                        docxTable.Rows[i].Cells[j].RemoveParagraphAt(0);
                        docxTable.Rows[i].MergeCells(j - 1, j);
                        colnum--;
                    }
                    else
                    {
                        j++;
                    }
                }
            }
            #endregion
        }
Esempio n. 3
0
        public static List <Offset> getOffsetCommands(Xceed.Words.NET.Table dataTable)
        {
            List <Offset> offsetList = new List <Offset>();

            string offsetOffset, offsetMask, offsetType, offsetUnits, offsetDescription;

            var rowList = dataTable.Rows;

            //the first row just says "offset", "mask","type","units", etc. skip it.
            for (int i = 1; i < rowList.Count; i++)
            {
                var cellList = rowList.ElementAt(i).Cells;

                //get the offset values
                offsetOffset = cellList.ElementAt(0).Paragraphs.ElementAt(0).Text;

                //get the mask
                offsetMask = "";
                for (int j = 0; j < cellList.ElementAt(1).Paragraphs.Count; j++)
                {
                    offsetMask = offsetMask + "\n" + cellList.ElementAt(1).Paragraphs.ElementAt(j).Text;
                }

                //get the type
                offsetType = cellList.ElementAt(2).Paragraphs.ElementAt(0).Text;

                //get the units
                offsetUnits = cellList.ElementAt(3).Paragraphs.ElementAt(0).Text;

                //get the description
                offsetDescription = "";
                for (int k = 0; k < cellList.ElementAt(4).Paragraphs.Count; k++)
                {
                    offsetDescription = offsetDescription + "\n" + cellList.ElementAt(4).Paragraphs.ElementAt(k).Text;
                }

                //add to the list
                Offset nextOffset = new Offset(offsetOffset, offsetMask, offsetType, offsetUnits, offsetDescription);
                offsetList.Add(nextOffset);
            }

            return(offsetList);
        }
Esempio n. 4
0
        public static void GenerateFeatureSpecDocument(Feature feature, DocX doc)
        {
            string title = feature.Name;

            Formatting titleFormat = new Formatting();

            titleFormat.FontFamily = new Xceed.Words.NET.Font("Arial");
            titleFormat.Size       = 13D;
            titleFormat.Position   = 10;
            titleFormat.FontColor  = System.Drawing.Color.Black;
            titleFormat.Bold       = true;

            doc.InsertParagraph(title, false, titleFormat);

            int rows = GetNumberOfRows(feature);

            Xceed.Words.NET.Table t = doc.AddTable(rows, 2);
            t.Alignment = Alignment.center;
            t.Rows[0].Cells[0].Paragraphs.First().Append("FS_Id");
            t.Rows[0].Cells[1].Paragraphs.First().Append("Requirement");

            t.Rows[0].Cells[0].Paragraphs.First().Bold();
            t.Rows[0].Cells[1].Paragraphs.First().Bold();

            int InsertDataToThisRowNext = 1;

            foreach (var child in feature.Children)
            {
                string FS_ID;
                string Requirement;

                if (child.Keyword.ToString().Equals("Scenario"))
                {
                    var scenario = (Scenario)child;

                    FS_ID       = scenario.Tags.ElementAt(0).Name.ToString().Substring(7);
                    Requirement = scenario.Name;
                }
                else if (child.Keyword.ToString().Equals("Scenario Outline"))
                {
                    var scenario = (ScenarioOutline)child;

                    FS_ID       = scenario.Tags.ElementAt(0).Name.ToString().Substring(7);
                    Requirement = scenario.Name;
                }
                else
                {
                    continue;
                }

                t.Rows[InsertDataToThisRowNext].Cells[0].Paragraphs.First().Append(FS_ID);

                t.Rows[InsertDataToThisRowNext].Cells[1].Paragraphs.First().Append(Requirement);

                InsertDataToThisRowNext++;
            }

            doc.InsertTable(t);

            string FooterWhiteSpace = "\n\n\n\n";

            doc.InsertParagraph(FooterWhiteSpace);

            doc.Save();
        }
Esempio n. 5
0
        //returns the list of commands AND replies from the file
        public static List <Command> getCommands(DocX docx)
        {
            List <Command> commandList = new List <Command>();
            var            paraList    = docx.Paragraphs;

            Xceed.Words.NET.Paragraph currentP;
            string commandPayloadName, commandReplyName, commandDescription;
            bool   commandIsCommand;
            UInt32 commandReplyValue, commandPayloadType;

            //this is all default values for the first command in the list, which is a command that does nothing
            commandPayloadType = 0;
            commandPayloadName = "no message payload";
            commandIsCommand   = false;
            List <Offset> firstCommandOffsets = null;

            commandReplyName   = "None";
            commandReplyValue  = 0;
            commandDescription = "None";
            Command firstCommand = new Command(commandPayloadType, commandPayloadName, commandIsCommand, firstCommandOffsets, commandReplyName, commandReplyValue, commandDescription);

            commandList.Add(firstCommand);

            for (int i = 0; i < paraList.Count; i++)
            {
                currentP = paraList.ElementAt(i);
                if (paraList.ElementAt(i).Text.Equals("Payload Name"))
                {
                    if (paraList.ElementAt(i - 1).Text.Equals("command"))
                    {
                        commandIsCommand   = true;
                        commandPayloadName = paraList.ElementAt(i + 1).Text + " command";
                        commandReplyName   = paraList.ElementAt(i + 5).Text;
                        commandReplyValue  = Convert.ToUInt32(paraList.ElementAt(i + 7).Text);
                    }
                    else
                    {
                        commandIsCommand   = false;
                        commandPayloadName = paraList.ElementAt(i + 1).Text + " reply";
                        commandReplyName   = "None";
                        commandReplyValue  = 0;
                    }
                    commandPayloadType = Convert.ToUInt32((paraList.ElementAt(i + 3).Text), 2);

                    //should never actually be null
                    Xceed.Words.NET.Table testTable = null;
                    commandDescription = "";
                    for (int j = i + 8; !(paraList.ElementAt(j).Equals("Offset")); j++)
                    {
                        commandDescription = commandDescription + paraList.ElementAt(j).Text;
                        if (paraList.ElementAt(j).FollowingTable != null)
                        {
                            testTable = paraList.ElementAt(j).FollowingTable;
                            break;
                        }
                    }
                    List <Offset> commandOffsets = getOffsetCommands(testTable);

                    Command nextCommand = new Command(commandPayloadType, commandPayloadName, commandIsCommand,
                                                      commandOffsets, commandReplyName, commandReplyValue, commandDescription);
                    commandList.Add(nextCommand);
                }
            }

            return(commandList);
        }
Esempio n. 6
0
        private void createDocxFile(string acum, string cardList, string adresa, double sumaTotala)
        {
            try
            {
                // Create a document in memory:
                var doc = DocX.Create(fileName);

                var titluFormat = new Formatting();
                titluFormat.FontFamily = new Xceed.Words.NET.Font("Arial");
                titluFormat.Size       = 20;
                titluFormat.Bold       = true;
                titluFormat.Position   = 100;
                doc.InsertParagraph("Receipt", false, titluFormat);

                var infoFormat = new Formatting();
                infoFormat.FontFamily = new Xceed.Words.NET.Font("Arial");
                infoFormat.Size       = 14;


                var headerFormat = new Formatting();
                headerFormat.Size = 14;
                headerFormat.Bold = true;

                var formatT = new Formatting();
                formatT.Size = 14;


                Xceed.Words.NET.Table t = doc.AddTable(4, 2);
                t.Rows[0].Cells[0].Paragraphs.First().Append("User  ", headerFormat);
                t.Rows[1].Cells[0].Paragraphs.First().Append("Date  ", headerFormat);
                t.Rows[2].Cells[0].Paragraphs.First().Append("Products  ", headerFormat);
                t.Rows[3].Cells[0].Paragraphs.First().Append("Address  ", headerFormat);

                t.Rows[0].Cells[1].Paragraphs.First().Append(fullname, formatT);
                t.Rows[1].Cells[1].Paragraphs.First().Append(acum, formatT);
                t.Rows[2].Cells[1].Paragraphs.First().Append(cardList, formatT);
                t.Rows[3].Cells[1].Paragraphs.First().Append(adresa, formatT);

                t.SetColumnWidth(1, 5000);
                t.SetColumnWidth(0, 5000);

                t.SetTableCellMargin(TableCellMarginType.top, 1000);
                t.SetTableCellMargin(TableCellMarginType.left, 1000);
                var sumaFormat = new Formatting();
                sumaFormat.FontFamily = new Xceed.Words.NET.Font("Arial");
                sumaFormat.Size       = 17;
                titluFormat.Bold      = true;

                doc.InsertTable(t);
                doc.InsertParagraph(Environment.NewLine + Environment.NewLine + " Total amount " + sumaTotala + " lei", false, sumaFormat);

                // Save to the output directory:
                doc.Save();

                createdDocx = true;
            }
            catch (Exception ex)
            {
                createdDocx = false;
            }
        }
Esempio n. 7
0
        private void ExportWord()
        {
            // Set file path
            string fileName  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string extension = ".docx";

            fileName += @"\example" + extension;

            // Create file
            var doc = DocX.Create(fileName);

            // Set the document margins
            doc.MarginLeft   = 40f;
            doc.MarginRight  = 40f;
            doc.MarginTop    = 40;
            doc.MarginBottom = 40f;

            // Create Table with rows and columns
            Xceed.Words.NET.Table t = doc.AddTable(dataGridMileageLogs.Items.Count + 1, 7);
            t.Alignment = Alignment.center;
            t.Design    = TableDesign.TableGrid;

            // Set the header colours
            t.Rows[0].Cells[0].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[1].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[2].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[3].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[4].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[5].FillColor = System.Drawing.Color.LightGray;
            t.Rows[0].Cells[6].FillColor = System.Drawing.Color.LightGray;

            Formatting boldFormatting = new Formatting();

            boldFormatting.Bold = true;

            // Set the header titles
            t.Rows[0].Cells[0].Paragraphs.First().Append("Date", boldFormatting);
            t.Rows[0].Cells[1].Paragraphs.First().Append("Start Time", boldFormatting);
            t.Rows[0].Cells[2].Paragraphs.First().Append("Starting Point", boldFormatting);
            t.Rows[0].Cells[3].Paragraphs.First().Append("Destination", boldFormatting);
            t.Rows[0].Cells[4].Paragraphs.First().Append("Classification", boldFormatting);
            t.Rows[0].Cells[5].Paragraphs.First().Append("Details", boldFormatting);
            t.Rows[0].Cells[6].Paragraphs.First().Append("Total Kilometres Driven", boldFormatting);

            int count = 0;

            var itemsSource = dataGridMileageLogs.ItemsSource;

            if (itemsSource != null)
            {
                foreach (var item in itemsSource)
                {
                    var row = dataGridMileageLogs.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
                    if (row != null)
                    {
                        count++;
                        MileageLog logEntry = (MileageLog)row.Item;
                        t.Rows[count].Cells[0].Paragraphs.First().Append(logEntry.Date);
                        t.Rows[count].Cells[1].Paragraphs.First().Append(logEntry.StartTime);
                        t.Rows[count].Cells[2].Paragraphs.First().Append(logEntry.StartingPoint);
                        t.Rows[count].Cells[3].Paragraphs.First().Append(logEntry.Destination);
                        t.Rows[count].Cells[4].Paragraphs.First().Append(logEntry.Purpose);
                        t.Rows[count].Cells[5].Paragraphs.First().Append(logEntry.PurposeDetails);
                        t.Rows[count].Cells[6].Paragraphs.First().Append(logEntry.TotalDistance.ToString("F"));
                    }
                }
            }

            // Insert Table
            doc.InsertTable(t);

            // Save document
            doc.Save();

            // Start Word
            Process.Start("WINWORD.EXE", fileName);
        }