2013-04-05 66 views
1

我已经从1996年的UNIX机器生成以下输出...我们正在升级为Windows的软件,我需要有一些问题从C#旧打印机文本格式C#

创建这个精确的输出http://pastebin.com/YBHpSYDW我无法处理,因为我不知道如何...

如何确定列,将“IMPORTE”列的对齐设置为正确,如果它是明文?

我已经做了在Excel这个输出是更具可读性,灵活..但他们希望这个令人毛骨悚然的老东西因为很多原因他们,我会变得疯狂了这个工作的人,他们不希望升级任何东西,只是软件,但保持每一个古老的令人毛骨悚然的东西@输出...

因此,如果有人知道一种方式来做到这一点,这将是非常有益的,谢谢。

编辑 输出是从SQL Server数据的列表,旧数据被存储到多值.DAT和.IDX文件,但现在他们在SQL Server ...所以基本上,代码产生的值是以下

var Query = getRows(sel.DataTable).Select(row => 
{ 
    return new 
    { 
     banco = row["banco"].ToString(), 
     emisora = row["emisora"].ToString(), 
     sucursal = row["sucursal"].ToString(), 
     fecha = row["fecha"].ToString(), 
     identificacion = row["identificacion"].ToString(), 
     importe = row["importe"].ToString(), 
     importe_dec = row["importe_dec"].ToString(), 
     provincia = row["provincia"].ToString(), 
     referencia = row["referencia"].ToString(), 
    }; 
}); 

然后我做了一些的foreach使魔...例如

foreach (var banco in Query.GroupBy(l => l.banco)) 

所以问题是打印输出文件...

EDIT 2 得到它的工作,这里的代码

private void generarFicheroPrt() 
{ 
    try 
    { 
     SelectBD sel = new SelectBD(Program.ConexBD, "SELECT * FROM Seguros"); 
     var Query = getRows(sel.DataTable).Select(row => 
     { 
      return new 
      { 
       banco = row["banco"].ToString(), 
       emisora = row["emisora"].ToString(), 
       sucursal = row["sucursal"].ToString(), 
       fecha = row["fecha"].ToString(), 
       identificacion = row["identificacion"].ToString(), 
       importe = row["importe"].ToString(), 
       importe_dec = row["importe_dec"].ToString(), 
       provincia = row["provincia"].ToString(), 
       referencia = row["referencia"].ToString(), 
      }; 
     }); 
     using (StreamWriter sw = new StreamWriter(Program.path + @"\CV9005.prt")) 
     { 
      int i = 1; 
      int pag = 0; 
      int linea = 1; 
      sw.WriteLine(); 
      sw.WriteLine("\x1b&l1O\x1b(s14H"); 
      decimal total = 0; 
      foreach (var valor in Query.OrderBy(l => l.emisora)) 
      { 
       if (linea == 48) linea = 1; 
       if (linea == 1) 
       { 
        pag++; 
        sw.WriteLine("\xc\t0125 BANCOFAR" + string.Empty.PadLeft(37, '\x20') + "COBRO POR VENTANILLA S. S. - CONTROL DE DOCUMENTOS  PAG.  "+ pag +"\n\n"); 
        sw.WriteLine("\t N.ORDEN NUMERO REFERENCIA   IMPORTE SUC. EMISORA"); 
        sw.WriteLine("\t ------- ----------------- ---------------- ---- -----------------------------------------------------------"); 
        sw.WriteLine(); 
       } 
       setSufijoEmisora(valor.emisora); 
       decimal importe = Convert.ToDecimal(Int32.Parse(valor.importe) + "," + valor.importe_dec); 
       string imp = importe.ToString("N2", Cultures.Spain); 
       sw.WriteLine("\t\t" + string.Format("{0, 4}\t{1, -13}\t\t{2, 13}{3,6} {4, -59}", i.ToString(), valor.referencia, imp, valor.sucursal, valor.emisora + " " + sufijoEmisora)); 
       i++; 
       linea++; 
       total = total + importe; 
      } 
      sw.WriteLine(); 
      sw.WriteLine("\t\t\t\t\t TOTAL .....\t" + string.Format("{0, 13}", total.ToString("N2", Cultures.Spain))); 
     }; 
    } 
    catch (Exception ex) 
    { 
     Logger.log(ex); 
    } 
} 
+0

u能请详细一点更像你是如何产生的输出?你使用表来产生这个输出吗?相关的代码片段将对提供任何建议非常有帮助。 – Raman 2013-04-05 08:13:05

+0

用生成输出的代码进行更新。 – 2013-04-05 08:18:09

+1

您将输出到控制台上的哪个位置输出到文本文件?直接打印机?如果要输出到文本文件,则可以使用工具箱中的“PrintDocument”工具并根据需要格式化文档;或者如果你想创建一个word文档,然后使用“Microsoft.Office.Core”库。这个库有一个文档属性,你可以编辑很多像你一样的单词。http://msdn.microsoft.com/en-us/library/microsoft.office.core.aspx – Jegan 2013-04-05 08:20:43

回答

1

使用工具箱中的 “PrintDocument的” 工具。

http://msdn.microsoft.com/en-gb/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx

这将帮助你与基本格式化。

编辑

更多更丰富的格式化,并保存到文件中使用Microsoft.Office.Core命名空间,

http://msdn.microsoft.com/en-us/library/microsoft.office.core.aspx

如果想要使用非ASCII编码,请务必将编码根据您的要求并使用所需的编码保存文件。

http://msdn.microsoft.com/en-us/library/microsoft.office.core.msoencoding.aspx

using(StreamWriter writer = new StreamWriter("a.txt", false, Encoding.UTF8)) 
{ 
    writer.WriteLine(s); 
} 
+0

这实际上将发送到打印机,我需要创建一个纯文本文件,所以我们可以打印它,也可以通过电子邮件发送例如,或只是保存在我们的电脑上... – 2013-04-05 08:36:03

+0

请参阅我的编辑链接到文档属性和以unicode保存文件。 – Jegan 2013-04-05 09:08:33