정보를 검색하고 Open XML SDK를 사용하여 .doc 형식으로 저장하면 모든 정보가 포함 된 문서가 하나만 있기 때문에 내 .doc 파일의 형식을 지정하고 싶습니다. 그리고 다른 형식의 정보는 포맷해야합니다.Open XML SDK 클래스를 사용하여 빈 줄을 삽입하는 방법
어떻게하면됩니까?
이
은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();
}
}
그리고 여기, 당신이 단순히에서 휴식 오브젝트와 실행을 만들고이 실행을 삽입 할 수 있습니다
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";
}
}
텍스트 t = 새 텍스트(); t.Text = conteudo; r.Append (새 CarriegeReturn()); r.Append (t); –