Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:09:33+00:00 2026-05-26T20:09:33+00:00

I want format my .doc file, because when I retrive information and save in

  • 0

I want format my .doc file, because when I retrive information and save in a .doc format using Open XML SDK, the document with all information is just in one line, and I need some information in other lines, just to format.

How can I do that?

This is my method that build an .doc

private static void BuildDocument(string fileName, string id, string conteudo)
        {
            Utilidade.QuebraToken tk2 = new Utilidade.QuebraToken();

            ////id = id.Remove(id.Length - 1);

            string select3 = "SELECT San_Imovel.TextoAnuncio, San_Imovel.Filial_Id, San_Imovel.NomeBairro,San_Imovel.TipoDsc1,San_Imovel.Imovel_Id,San_Filial.NomeFantasia ,San_ContatoFilial.Contato   " +
                                                "FROM San_Imovel    " +
                                                "JOIN San_Filial ON San_Imovel.Filial_Id = San_Filial.Filial_id " +
                                                "JOIN San_ContatoFilial ON San_Filial.Filial_Id = San_ContatoFilial.Filial_Id " +
                                                "WHERE Imovel_Id IN (" + id + ") " +
                                                " AND San_ContatoFilial.TipoContatoFilial_Id = 1";    

            using (WordprocessingDocument w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
            {
                MainDocumentPart mp = w.AddMainDocumentPart();
                DocumentFormat.OpenXml.Wordprocessing.Document d = new DocumentFormat.OpenXml.Wordprocessing.Document();
                Body b = new Body();
                DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
                Run r = new Run();
                Text t = new Text();
                t.Text = conteudo;
                r.Append(t);
                p.Append(r);
                b.Append(p);
                HeaderPart hp = mp.AddNewPart<HeaderPart>();
                string headerRelationshipID = mp.GetIdOfPart(hp);
                SectionProperties sectPr = new SectionProperties();
                HeaderReference headerReference = new HeaderReference();
                headerReference.Id = headerRelationshipID;
                headerReference.Type = HeaderFooterValues.Default;
                sectPr.Append(headerReference);
                b.Append(sectPr);
                d.Append(b);
                hp.Header = BuildHeader(hp, "Anuncio");
                hp.Header.Save();
                mp.Document = d;
                mp.Document.Save();
                w.Close();
            }
        }

And here, I call this method

public static object GerarDoc(string id, string email, string veiculo)
        {
            try
            {

            id = id.Remove(id.Length - 1);

            string conteudo = string.Empty;

            string select3 = "SELECT San_Imovel.TextoAnuncio, San_Imovel.Filial_Id, San_Imovel.NomeBairro,San_Imovel.TipoDsc1,San_Imovel.Imovel_Id,San_Filial.NomeFantasia ,San_ContatoFilial.Contato   " +
                                                "FROM San_Imovel                                                                                                                                                                                                                                                                                                                                                                                " +
                                                "INNER JOIN San_Filial ON San_Imovel.Filial_Id = San_Filial.Filial_id                                                                                                                                                                                                                                                                       " +
                                                "INNER JOIN San_ContatoFilial ON San_Filial.Filial_Id = San_ContatoFilial.Filial_Id                                                                                                                                                                                                                                                         " +
                                                "WHERE Imovel_Id IN (" + id + ")                                                                                                                                                                                                                                                                                                                                                                " +
                                                "AND San_ContatoFilial.TipoContatoFilial_Id = 1                                                                                                                                                                                                                                                                                                                             ";            

            Utilidade.Conexao c3 = new Utilidade.Conexao();
            SqlConnection con3 = new SqlConnection(c3.Con);
            SqlCommand cmd3 = new SqlCommand(select3, con3);
            con3.Open();
            SqlDataReader r3 = cmd3.ExecuteReader();
            while (r3.Read())
            {
                conteudo = conteudo + "" + (r3["Contato"]) + "";                
                conteudo = conteudo + "\n"+ (r3["NomeBairro"]);
                conteudo = conteudo + "\n" + (r3["TipoDsc1"]) ;
                conteudo = conteudo + "\n" + (r3["NomeFantasia"]) + " (" + (r3["Imovel_Id"]) + ") " + (r3["TextoAnuncio"]) + "\n\n";
            }            
            con3.Close();

                Random rnd = new Random (DateTime.Now.Millisecond);

                string NomeArquivo = "Anuncio_" + Credenciada + "_" + Usuario + "_" + rnd.Next().ToString();                
                rng.Font.Name = "Arial";                    
                rng.Text = conteudo;

                BuildDocument(@"C:\inetpub\wwwroot\galileu.redenetimoveis.com\Anuncios\" + NomeArquivo + ".doc", id, rng.Text); 

                retorno = "1";                
            }       

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:09:33+00:00Added an answer on May 26, 2026 at 8:09 pm

    You can simply create a run with a break object in it and insert this run in your code everytime a page break is required, please see below for an example:

    using (WordprocessingDocument package = WordprocessingDocument.Create("D:\\LineBreaks.docx", WordprocessingDocumentType.Document))
    {
        package.AddMainDocumentPart();
    
        Run run1 = new Run();
        Text text1 = new Text("The quick brown fox");
        run1.Append(text1);
    
        Run lineBreak = new Run(new Break());
    
        Run run2 = new Run();
        Text text2 = new Text("jumps over a lazy dog");
        run2.Append(text2);
    
        Paragraph paragraph = new Paragraph();
        paragraph.Append(new OpenXmlElement[] { run1, lineBreak, run2 });
    
        Body body = new Body();
        body.Append(paragraph);
    
        package.MainDocumentPart.Document = new Document(new Body(body));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send an xml document that i have created using jdom api.
Basicaly I want to format a Date object using a specific pattern and the
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov
I want to view .doc, .docx, .rtf, .ppt file in iphone. But I guess
I'm going to start the development of my own document format(like PDF, XPS, DOC,
i store doc file into sql server data base i want view this file
I want to convert a doc file to txt file, but some characters are
I want to make a .EMF file (or other format, see below) to use
I am writing some code to parse an xml file of the following format
I have the following xml file: <root> <sub type=print>print</sub> <sub type=email>email</sub> </root> I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.