Ejemplo n.º 1
0
        private static List<Entry> ReadCembraCsv(string file)
        {
            List<Entry> entries = new List<Entry>();
            try
            {
                string filename = "C:\\temp\\cc1414484476802.xls";
                Application _excelApp = new Application();
                Workbook workBook = _excelApp.Workbooks.Open(filename,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                    Type.Missing, Type.Missing);

                Worksheet sheet = (Worksheet)workBook.Sheets["Report"];
                Range excelRange = sheet.UsedRange;
                object[,] valueArray = (object[,])excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);

                for (int y = 8; y < valueArray.GetLength(0); y++)
                {
                    string date = valueArray[y, 1].ToString();
                    string desc = valueArray[y, 4].ToString();
                    string amount = valueArray[y, 6].ToString().Replace("CHF", string.Empty);
                    Entry entry = new Entry
                    {
                        Amount = Double.Parse(amount),
                        Date = DateTime.Parse(date),
                        Text = desc
                    };
                    entries.Add(entry);
                }

                workBook.Close(false, filename, null);
                Marshal.ReleaseComObject(workBook);
            }
            catch (Exception x)
            {
                Console.WriteLine(x.ToString());
            }

            return entries;
        }
Ejemplo n.º 2
0
        private static void ReadSammelauftrag(StreamReader sr, List<Entry> entries, double amount)
        {
            Entry result = new Entry {Amount = amount, Text = "Sammelauftrag: "};
            string sammelAuftragLine;
            while ((sammelAuftragLine = sr.ReadLine()) != null)
            {
                string[] data = sammelAuftragLine.Split(';');

                string text = data[1];

                if (string.IsNullOrEmpty(data[0])) // Data for Sammelauftrag
                {
                    result.Text += " / " + text;
                }
                else
                {
                    entries.Add(result);

                    DateTime date = !string.IsNullOrEmpty(data[0]) ? DateTime.Parse(data[0]) : DateTime.MinValue;
                    double regularEntryAmount = !string.IsNullOrEmpty(data[2]) ? Double.Parse(data[2]) : 0;

                    entries.Add(new Entry {Date = date, Text = text, Amount = regularEntryAmount});
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private static List<Entry> ReadBankCsv(string file)
        {
            List<Entry> entries = new List<Entry>();
            Entry lastEntry = new Entry();
            using (StreamReader sr = new StreamReader(file, Encoding.GetEncoding("iso-8859-1")))
            {
                string line;
                int lineCount = 1;
                while ((line = sr.ReadLine()) != null)
                {
                    // Skip header
                    if (lineCount == 1)
                    {
                        lineCount++;
                        continue;
                    }

                    string[] data = line.Split(';');
                    DateTime date = !string.IsNullOrEmpty(data[0]) ? DateTime.Parse(data[0]) : DateTime.MinValue;
                    string text = data[1].Replace('\t',' ').Trim();
                    double amount = !string.IsNullOrEmpty(data[2]) ? Double.Parse(data[2]) : 0;

                    if (date == DateTime.MinValue)
                    {
                        lastEntry.Text += " / " + text;
                        lastEntry.IsSammelauftrag = true;

                        if (lastEntry.Text.Contains("Sammelauftrag"))
                        {
                            Entry subEntry = new Entry
                            {
                                Date = lastEntry.Date,
                                Text = text,
                                Amount = GetAmountFromSubEntry(text)
                            };
                            entries.Add(subEntry);
                        }

                        lineCount++;
                        continue;
                    }

                    lastEntry = new Entry {Date = date, Text = text, Amount = amount};
                    entries.Add(lastEntry);

                    lineCount++;
                }

                sr.Close();
            }

            return entries;
        }