示例#1
0
文件: Convettxt.cs 项目: mathewsun/My
        public ExcelWorksheet ConvtxtScalar(ZnachView path, ExcelPackage excel, String scalare)
        {
            var i = 0;

            // var scal = System.Convert.ToChar(scalare);
            using (var st = new StreamReader(path.Pathfile, Encoding.Default))
            {
                var worksheet = excel.Workbook.Worksheets.Add(path.Namefile);

                while (!st.EndOfStream)
                {
                    var readLine = st.ReadLine();
                    if (readLine != null)
                    {
                        i++;

                        worksheet.Cells[String.Format("A{0}", i)].Value = readLine;
                        foreach (var cell in worksheet.Cells[String.Format("A{0}", i)])
                        {
                            var splittedValues = Regex.Split((String)cell.Value, scalare);
                            cell.Value = splittedValues[0];
                            for (var j = 0; j < splittedValues.Length; j++)
                            {
                                worksheet.Cells[cell.Start.Row, cell.Start.Column + j].Value = splittedValues[j];
                            }
                        }
                    }
                }
                worksheet.Cells.AutoFitColumns();
                st.Dispose();
                return(worksheet);
            }
        }
示例#2
0
        internal void AddFile(object sender, RoutedEventArgs e)
        {
            var i = new ZnachView {
                File = new ObservableCollection <ZnachView>()
            };
            var win = new OpenFileDialog {
                Filter = "Файлы txt|*.txt|Файлы crv|*crv|Файлы tsv|*tsv", Multiselect = true
            };

            if (win.ShowDialog() == true)
            {
                foreach (string file in win.FileNames)
                {
                    i.File.Add(new ZnachView {
                        NameFile = Path.GetFileNameWithoutExtension(file), PathFile = Path.GetFullPath(file)
                    });
                }
                P2.ListFile.Dispatcher.Invoke(() => P2.ListFile.ItemsSource = i.File);
            }
        }
示例#3
0
文件: Convettxt.cs 项目: mathewsun/My
        public ExcelWorksheet ConvtxtFull(ZnachView path, ExcelPackage excel)
        {
            int i = 0;

            using (var st = new StreamReader(path.Pathfile, Encoding.Default))
            {
                var worksheet = excel.Workbook.Worksheets.Add(path.Namefile);
                while (!st.EndOfStream)
                {
                    var readLine = st.ReadLine();
                    if (readLine != "")
                    {
                        i++;
                        worksheet.Cells[String.Format("A{0}", i)].Value = readLine;
                    }
                }
                worksheet.Cells.AutoFitColumns();
                st.Dispose();
                return(worksheet);
            }
        }