QuickBooks和Sage数据导出器

许多中小企业都使用QuickBooks作为其会计模块。 同样,许多公司也使用Sage进行会计处理。 他们中的大多数人在需要从这些系统中导出数据时会遇到问题。

在线提供的许多连接器价格昂贵,无法满足确切的要求。 随附的是一些简短的代码段,这些代码段说明了如何将数据导出到CSV。 我还附加了github链接来下载代码。

SAGE和Quickbook都带有ODBC驱动程序,可以对它们进行配置和编程查询

#智者

在ODBC数据源中创建一个静默ODBC DSN。

QuickBooks

在“选项”选项卡中配置静默模式。

QuickBooks

现在,我们将使用下面的数据源加载和导出数据。

我们将使用DotNet Core将我们的代码编写为与Windows上的DSN交流的最佳语言。

我将问题分为3个部分

  1. 从数据库加载表名
  2. 为每个表加载数据集
  3. 将每个表从DataSet导出到CSV
private static List loadTableNames(string connectionString){
            var tableNames = new List();

            using (OdbcConnection connection =
					   new OdbcConnection(connectionString))
			{
                try
				{
					connection.Open();
					using(DataTable tableschema = connection.GetSchema("Tables"))
                    {
                        // first column name
                        foreach(DataRow row in tableschema.Rows)
                        {
                            tableNames.Add(row["TABLE_NAME"].ToString());
                            //Console.WriteLine(row["TABLE_NAME"].ToString());
                        }
                    }
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
				}

            }

            return tableNames;

        }

现在我们需要编写代码以加载给定表的数据。 在这种情况下,我将使用DataSet。 有很多方法可以做到这一点。

public static DataSet GetDataSetFromAdapter(
			DataSet dataSet, string connectionString, string queryString)
		{
			using (OdbcConnection connection =
					   new OdbcConnection(connectionString))
			{

				OdbcDataAdapter adapter =
					new OdbcDataAdapter(queryString, connection);

				// Open the connection and fill the DataSet.
				try
				{
					connection.Open();
					adapter.Fill(dataSet);
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
				}
				// The connection is automatically closed when the
				// code exits the using block.
			}
			return dataSet;
		}

最后是将所有数据导出到CSV的功能

<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>
        private static string ConvertToCSV(DataSet objDataSet)
        {
            StringBuilder content = new StringBuilder();

            if (objDataSet.Tables.Count >= 1)
            {
                DataTable table = objDataSet.Tables[0];

                if (table.Rows.Count > 0)
                {
                    DataRow dr1 = (DataRow) table.Rows[0];
                    int intColumnCount = dr1.Table.Columns.Count;
                    int index=1;

                    //add column names
                    foreach (DataColumn item in dr1.Table.Columns)
                    {
                        content.Append(String.Format("\"{0}\"", item.ColumnName));
                        if (index < intColumnCount)
                            content.Append(",");
                        else
                            content.Append("\r\n");
                        index++;
                    }

                    //add column data
                    foreach (DataRow currentRow in table.Rows)
                    {
                        string strRow = string.Empty;
                        for (int y = 0; y <= intColumnCount - 1; y++)
                        {
                            strRow += "\"" + currentRow[y].ToString() + "\"";

                            if (y = 0)
                                strRow += ",";
                        }
                        content.Append(strRow + "\r\n");
                    }
                }
            }

            return content.ToString();
        }

https://github.com/ashwinrayaprolu1984/SageDataExporter.git

#QuickBooks

对于QuickBooks,我们采用相同的方法。

  1. 从文件中加载表名(Quickbooks不在其ODBC数据源中导出架构)
  2. 为每个表加载数据集
  3. 将每个表从DataSet导出到CSV

git hub下面的链接具有执行此操作的代码

https://github.com/ashwinrayaprolu1984/QuickBooksDesktopConnector.git

翻译自: https://www.javacodegeeks.com/2018/11/quickbooks-sage-data-exporter.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值