Skip to content

Instantly share code, notes, and snippets.

@smarenich
Last active March 29, 2016 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarenich/221df85fed64edf4b867 to your computer and use it in GitHub Desktop.
Save smarenich/221df85fed64edf4b867 to your computer and use it in GitHub Desktop.
private static void ImportTransactionsFromFile(PX.SM.FileInfo file)
{
ImportTest graph = new ImportTest();
Byte[] bytes = file.BinData;
using(PX.Data.XLSXReader reader = new XLSXReader(bytes))
{
//Initialising Reader
reader.Reset();
//Creating a dictionary to find column index by name
Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value, p => p.Key);
//Skipping first row with collumns names.
reader.MoveNext();
while(reader.MoveNext())
{
Tran row = graph.Transactions.Insert();
//Transforming External representation to Internal by using SetValueExt method.
graph.Transactions.Cache.SetValueExt(row, "AccountID", reader.GetValue(indexes["Account"]));
graph.Transactions.Cache.SetValueExt(row, "SubID", reader.GetValue(indexes["Account"]));
//Converting to Decimal
row.Qty = Decimal.Parse(reader.GetValue(indexes["Quantity"]));
row.DebitAmt = Decimal.Parse(reader.GetValue(indexes["Debit Amount"]));
row.CreditAmt = Decimal.Parse(reader.GetValue(indexes["Credit Amount"]));
row = graph.Transactions.Update(row);
}
graph.Actions.PressSave();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment