printing - Old printer text format c# -


i have following output generated unix machine 1996... upgrading software windows, , need create exact output http://pastebin.com/ybhpsydw c#

there problems can't handle, because don't know how...

how can determinate columns, set aligment "importe" column right, if plaintext?

i have done output in excel more readable, flexible.. want creepy old stuff because lot of reasons , i'll become insane working people, don't want upgrade anything, software keep every old creepy thing @ output...

so if knows way this, it'll helpful, thank you.

edit output list of data sql server, old data stored multivalue .dat , .idx files, they're in sql server... basically, code generates values 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 foreach make magic... example

foreach (var banco in query.groupby(l => l.banco)) 

so problem output file printing...

edit 2 got working, here's code

private void generarficheroprt() {     try     {         selectbd sel = new selectbd(program.conexbd, "select * 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 = 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 "printdocument" tool toolbox.

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

this basic formating.

edit

for more richer formating , saving file use microsoft.office.core namespace,

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

if want non ascii encoding, make sure set encoding per requirement , save file 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); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -