public void Dispose() { // Keep the file. if (_reader != null) { _reader.Close(); } _reader = null; _columnNames = null; _rows = null; _filename = null; }
public void Dispose() { // Keep the file. _columnNames = null; _rows = null; }
private void LoadRows() { using (Package pkg = Package.Open(_zipFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { PackagePart part = pkg.GetPart(_zipUri); using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read)) using (StreamReader r = new StreamReader(s)) { if (r.EndOfStream) { throw new Exception("CSV header missing"); } string line = r.ReadLine(); _columnNames = line.Split(','); int i, j, c; bool inString = false, haveString = false; _rows = new CSVRowList(); string[] objects = new string[12]; while (!r.EndOfStream) { line = r.ReadLine(); j = 0; c = 0; haveString = false; for (i = 0; i < line.Length; i++) { if (!inString) { if (line[i] == ',') { if (haveString) { objects[c] = line.Substring(j + 1, i - j - 2); } else { objects[c] = line.Substring(j, i - j); } c++; j = i + 1; haveString = false; } else if (line[i] == '\"') { inString = true; haveString = true; } } else { if (line[i] == '\\') { i++; } else if (line[i] == '\"') { inString = false; } } } _rows.Add(new CSVRow(objects)); } } } }