Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

OpenXML sortiranje tabele u wordu

[es] :: .NET :: OpenXML sortiranje tabele u wordu

[ Pregleda: 613 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

gogi100
Goran Ljubic

Član broj: 40722
Poruke: 1064
*.dynamic.isp.telekom.rs.



+3 Profil

icon OpenXML sortiranje tabele u wordu12.07.2021. u 19:52 - pre 33 meseci
imam word dokument, koji sluzi za smestanje zapisa koji se upisuju u ovaj word dokument u tabelu, kada se kreiraju u sharepoint listama. Potrebno je nakon unosa zapisa uraditi sortiranje tabele po koloni koja sadrzi datum. moj kod je

Code:
using (WordprocessingDocument doc = WordprocessingDocument.Open(memStr5, true))
                {


                    MainDocumentPart main = doc.MainDocumentPart;



                    Table TabelaEvidencijaPutnihNaloga = main.Document.Body.Descendants<Table>().First();
                    int brojredova = TabelaEvidencijaPutnihNaloga.Elements<TableRow>().Count();
                    TableRow Red = TabelaEvidencijaPutnihNaloga.Elements<TableRow>().Last();
               
                    TableRow rowCopy = (TableRow)Red.CloneNode(true);

                    brojredova = brojredova - 1;

                    rowCopy.Descendants<TableCell>().ElementAt(0).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(0).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(Convert.ToString(brojredova)))));
                    rowCopy.Descendants<TableCell>().ElementAt(1).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(1).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(dn.ToString()))));
                    rowCopy.Descendants<TableCell>().ElementAt(2).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(2).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(imeiprezime.ToString()))));
                    rowCopy.Descendants<TableCell>().ElementAt(3).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(3).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(lokacija.ToString() + "," + brojdananaputu.ToString() + " dan"))));
                    rowCopy.Descendants<TableCell>().ElementAt(4).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(4).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(razlogputovanja.ToString()))));
                    rowCopy.Descendants<TableCell>().ElementAt(5).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(5).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(vozilo.ToString()))));
                    rowCopy.Descendants<TableCell>().ElementAt(9).RemoveAllChildren<Paragraph>();
                    rowCopy.Descendants<TableCell>().ElementAt(9).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(napomena.ToString()))));


                    TabelaEvidencijaPutnihNaloga.AppendChild(rowCopy);
                
                 
                    TabelaEvidencijaPutnihNaloga.OrderBy(s => s.Elements<TableCell>().ElementAt(1)); //ovde sam pokusao da uradim sortiranje ali ne radi
                   



                    //closing WordprocessingDocument automatically saves the document
                }
 
Odgovor na temu

gogi100
Goran Ljubic

Član broj: 40722
Poruke: 1064
*.static.isp.telekom.rs.



+3 Profil

icon Re: OpenXML sortiranje tabele u wordu14.07.2021. u 12:25 - pre 33 meseci
pokusao sam i sa sledecim kodom ali imam problem sa row.insertbefore(CopyRow,row); javlja mi gresku Operation is not valid due to the current state of the object

Code:
 using (WordprocessingDocument doc = WordprocessingDocument.Open(memStr5, true))
                {


                    MainDocumentPart main = doc.MainDocumentPart;



                    Table TabelaEvidencijaPutnihNaloga = main.Document.Body.Descendants<Table>().First();
                    int brojredova = TabelaEvidencijaPutnihNaloga.Elements<TableRow>().Count();
                    TableRow Red = TabelaEvidencijaPutnihNaloga.Elements<TableRow>().Last();
                   
                    
                  
                     


                        // Remove the empty placeholder row from the table.
                        //   TabelaZapisnik.RemoveChild(Red);

                        for (int i = 3; i <= brojredova; i++)
                        {
                            TableRow row = TabelaEvidencijaPutnihNaloga.Elements<TableRow>().ElementAt(i-1);
                            if (Convert.ToDateTime(dn) < Convert.ToDateTime(row.Elements<TableCell>().ElementAt(1).InnerText))
                            {
                                
                                TableRow rowCopy = (TableRow)row.CloneNode(true);
                                rowCopy.Descendants<TableCell>().ElementAt(0).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(0).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(Convert.ToString(brojredova)))));
                                rowCopy.Descendants<TableCell>().ElementAt(1).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(1).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(dn.ToString()))));
                                rowCopy.Descendants<TableCell>().ElementAt(2).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(2).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(imeiprezime.ToString()))));
                                rowCopy.Descendants<TableCell>().ElementAt(3).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(3).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(lokacija.ToString() + "," + brojdananaputu.ToString() + " dan"))));
                                rowCopy.Descendants<TableCell>().ElementAt(4).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(4).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(razlogputovanja.ToString()))));
                                rowCopy.Descendants<TableCell>().ElementAt(5).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(5).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(vozilo.ToString()))));
                                rowCopy.Descendants<TableCell>().ElementAt(9).RemoveAllChildren<Paragraph>();
                                rowCopy.Descendants<TableCell>().ElementAt(9).Append(new Paragraph(new Run(new RunFonts() { Ascii = "Times New Roman" }, new Text(napomena.ToString()))));
                                TableRow tekucired = row.InsertBefore(rowCopy, row);
                                TabelaEvidencijaPutnihNaloga.AppendChild(tekucired);
                            }
                        }

                    //closing WordprocessingDocument automatically saves the document
                }
 
Odgovor na temu

[es] :: .NET :: OpenXML sortiranje tabele u wordu

[ Pregleda: 613 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.