Export to qif

May 11, 2010 at 10:05 PM

It could be posible to export to qif format passing a parameter for example a datatable, something like that

private void exportToQif(DataTable dt){

//do stuff

}

Coordinator
May 12, 2010 at 7:55 PM

Can you clarify the intended purpose?

May 12, 2010 at 8:39 PM

Of course,

I have a Web Grid with information about account statement, and I would like to import the information from the grid directly to qif format.

I populate the Grid with an asp Datable, so I would to use these Datatable in order to import the information.

 

The Grid looks like that:

Amount AccountingBalance AvailableBalance
10548.84 10548.84 10548.84
1.3 10550.14 10550.14
39 10589.14 10589.14
39.26 10628.4 10628.4
40.61 10669.01 10669.01
136.12 5150.46 5150.46

 

So, I´m creating and including an asp button on the grid that says "ExportToQif", and should be export to qif format, but I dont know how to do that,

the initial logic looks like:

 

public static void ExportToMoney(DataTable table, string name)
        {
            HttpContext context = HttpContext.Current;
            context.Response.Clear();
            context.Response.Write("!Type:Bank");
            context.Response.Write(Environment.NewLine);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                foreach (DataColumn column in table.Columns)
                {
                    if (column.ColumnName == "Date")
                    {
                        string date= table.Rows[i]["Date"].ToString();
                        context.Response.Write("D" + date);
                        context.Response.Write(Environment.NewLine);
                    }
                    if (column.ColumnName == "Amount")
                    {
                        double originalAmount= Convert.ToDouble(table.Rows[i]["Amount"]);

                        string amount= String.Format("{0:N}", originalAmount);
                        context.Response.Write("T"+amount);
                        context.Response.Write(Environment.NewLine);
                     
                                           }

                    if (column.ColumnName == "Description")
                    {
                        string descripcion = table.Rows[i]["Description"].ToString();
                        context.Response.Write("P" + descripcion);
                        context.Response.Write(Environment.NewLine);
                    }
                    

                }
                context.Response.Write("^");
                context.Response.Write(Environment.NewLine);

            }

 Any suggestion?

 

Coordinator
May 13, 2010 at 4:33 AM
Edited May 13, 2010 at 4:40 AM

Using this API you could do the same thing. Here is some sample code, but I did not compile or run this—it's all pseudo code. Hopefully it's enough to get you going using this API. 

public static void ExportToMoney(DataTable table, string name)
{
    HttpContext context = HttpContext.Current;
    string tempOutputFile = context.Server.MapPath(".") + @"\output\" + Guid.NewGuid().ToString() + ".qif";
    QifDom qd = new QifDom();

    context.Response.Clear();

    for (int i = 0; i < table.Rows.Count; i++)
    {
        BasicTransaction bt = new BasicTransaction();

        foreach (DataColumn column in table.Columns)
        {
            if (column.ColumnName == "Date")
            {
                bt.Date = DateTime.Parse(table.Rows[i]["Date"].ToString());
            }

            if (column.ColumnName == "Amount")
            {
                bt.Amount = Convert.ToDecimal(table.Rows[i]["Amount"]);
            }

            if (column.ColumnName == "Description")
            {
                bt.Payee = table.Rows[i]["Description"].ToString();
            }
        }

        qd.BankTransactions.Add(bt);
    }

    qd.Export(tempOutputFile);

    context.Response.WriteFile(tempOutputFile);
}