public static void SaveAsCsv(Ex.Relational.IRelationalSheet sheet, string path) {
            using (var s = new StreamWriter(path, false, Encoding.UTF8)) {
                var indexLine = new StringBuilder("key");
                var nameLine = new StringBuilder("#");
                var typeLine = new StringBuilder("int32");

                var colIndices = new List<int>();
                foreach (var col in sheet.Header.Columns) {
                    indexLine.AppendFormat(",{0}", col.Index);
                    nameLine.AppendFormat(",{0}", col.Name);
                    typeLine.AppendFormat(",{0}", col.ValueType);

                    colIndices.Add(col.Index);
                }

                s.WriteLine(indexLine);
                s.WriteLine(nameLine);
                s.WriteLine(typeLine);

                foreach (var row in sheet.Cast<Ex.IRow>().OrderBy(_ => _.Key)) {
                    s.Write(row.Key);
                    foreach (var col in colIndices) {
                        var v = row.GetRaw(col);

                        if (v == null)
                            s.Write(",");
                        else if (IsUnescaped(v))
                            s.Write(",{0}", v);
                        else
                            s.Write(",\"{0}\"", v.ToString().Replace("\"", "\"\""));
                    }
                    s.WriteLine();
                }
            }
        }
        public static void SaveAsCsv(Ex.Relational.IRelationalSheet sheet, Language language, string path) {
            using (var s = new StreamWriter(path, false, Encoding.UTF8)) {
                var indexLine = new StringBuilder("key");
                var nameLine = new StringBuilder("#");
                var typeLine = new StringBuilder("int32");

                var colIndices = new List<int>();
                foreach (var col in sheet.Header.Columns) {
                    indexLine.AppendFormat(",{0}", col.Index);
                    nameLine.AppendFormat(",{0}", col.Name);
                    typeLine.AppendFormat(",{0}", col.ValueType);

                    colIndices.Add(col.Index);
                }

                s.WriteLine(indexLine);
                s.WriteLine(nameLine);
                s.WriteLine(typeLine);

                foreach (var row in sheet.Cast<Ex.IRow>().OrderBy(_ => _.Key)) {
                    var useRow = row;

                    if (useRow is IXivRow)
                        useRow = ((IXivRow)row).SourceRow;
                    var multiRow = useRow as IMultiRow;

                    s.Write(useRow.Key);
                    foreach (var col in colIndices) {
                        object v;

                        if (language == Language.None || multiRow == null)
                            v = useRow[col];
                        else
                            v = multiRow[col, language];

                        if (v == null)
                            s.Write(",");
                        else if (IsUnescaped(v))
                            s.Write(",{0}", v);
                        else
                            s.Write(",\"{0}\"", v.ToString().Replace("\"", "\"\""));
                    }
                    s.WriteLine();

                    s.Flush();
                }
            }
        }
Esempio n. 3
0
        public static void SaveAsWiki(Ex.Relational.IRelationalSheet sheet, string path)
        {
            IDictionary<int, string> colIndicesToNames = new Dictionary<int, string>();

            using (var s = new StreamWriter(path, false, Encoding.UTF8))
            {
                foreach (var col in sheet.Header.Columns)
                {
                    colIndicesToNames[col.Index] = col.Name;
                }

                foreach (var row in sheet.Cast<Ex.IRow>().OrderBy(_ => _.Key))
                {
                    s.WriteLine("{{ARR Infobox Item");
                    s.WriteLine("|Index={0}", row.Key.ToString());

                    foreach(KeyValuePair<int, string> entry in colIndicesToNames)
                    {
                        var v = row[entry.Key];
                        var cName = entry.Value;
                        var nv = "";

                        if (cName != null && cName.ToString() != "" && v != null && v.ToString() != "") {
                            nv = v.ToString().Replace("\"", "\"\"");
                            nv = Regex.Replace(nv, @"\t|\n|\r", "");
                            s.WriteLine("|{0}=\"{1}\"", cName, nv);
                        }
                    }
                    s.WriteLine("}}");
                    s.WriteLine();
                    s.WriteLine();

                    s.Flush();
                }
            }
        }