문제

I have the following output generated by an UNIX machine from 1996... We are upgrading the software for Windows, and I need to create this exact output http://pastebin.com/YBHpSYDW from C#

There are some problems I can't handle, because I don't know how...

How can I determinate the columns, set aligment for the "IMPORTE" column to the right, if it is plaintext?

I have done this output in Excel which is more readable, flexible.. but they want this creepy old stuff because a lot of reasons and they I'll become insane working for this people, they don't want to upgrade anything, just the software but keep every old creepy thing @ output...

So if anyone knows a way to do this, it'll be so much helpful, thank you.

EDIT The output is a list of data from an SQL Server, old data was stored into MultiValue .DAT and .IDX files, but now they're in a SQL Server... So basically, the code that generates the values is the following

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(),
    };
});

Then I do some foreach to make the magic... For example

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

So the problem is the output file for printing...

EDIT 2 Got it working, here's the code

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);
    }
}
도움이 되었습니까?

해결책

Use the "PrintDocument" tool from the toolbox.

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

This will help you with basic formating.

Edit

For more richer formating and saving to file use the Microsoft.Office.Core namespace,

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

If you want non ASCII encoding, make sure to set the encoding as per your requirement and save the file with the required encoding.

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top