1. C# / Говнокод #19154

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using Excel;
    using FPCLib.Models.Broadcasts;
    
    namespace ExcelReadTests.Model.Путевка
    {
        public class MyExcel : IDisposable
        {
            private readonly DataTable table;
    
            public MyExcel(string putevkaFileName)
            {
                table = ReadToTable(putevkaFileName);
            }
    
    		  internal DataTable ReadToTable(string excelFileName)
            {
                var stream = File.Open(excelFileName, FileMode.Open, FileAccess.Read);
                var excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
    
                return excelReader.AsDataSet().Tables[0];
            }
    
            public bool IsTvc()
            {
                if (table.Columns.Count == 10)
                    return true;
                return false;
            }
    
            public bool IsFriday()
            {
                if (table.Columns.Count == 16)
                    return true;
                return false;
            }
    		
          
            public List<Broadcast> GetBroadcastsFriday()
            {
                var broadcasts = new List<Broadcast>();
                for (var i = 0; i < table.Rows.Count; i++)
                {
                    if (table.Rows[i][0].ToString().Length > 1)
                    {
                        broadcasts.Add(new Broadcast
                        {
                            Time = new Time(table.Rows[i][0].ToString()),
                            Title = table.Rows[i][1].ToString(),
                            File = table.Rows[i][3].ToString(),
                            Type = table.Rows[i][7].ToString(),
                            Id = table.Rows[i][2].ToString(),
                            Length = new Time(table.Rows[i][4].ToString())
                        });
                    }
                }
    
                return broadcasts;
            }
    
            public List<Broadcast> GetBroadcastsTvc()
            {
                var broadcasts = new List<Broadcast>();
                for (var i = 0; i < table.Rows.Count; i++)
                {
                    broadcasts.Add(new Broadcast
                    {
                        Time = new Time(table.Rows[i][0].ToString()),
                        Title = table.Rows[i][2].ToString().Trim(),
                        File = table.Rows[i][6].ToString().Trim(),
                        Type = table.Rows[i][9].ToString().Trim(),
                        Id = table.Rows[i][1].ToString().Trim(),
                        Length = new Time(table.Rows[i][5].ToString())
                    });
                }
    
                return broadcasts;
            }
    		
    		  public void Dispose()
            {
            }
          
        }
    }

    вот так открываю эксельку
    DataTable ReadToTable(string excelFileName)

    по количеству столбцов, определяю ее источник)
    public bool IsTvc()
    public bool IsFriday()



    и даже поддерживаю интерфейс IDisposable))

    Запостил: yolozesoja, 08 Декабря 2015

    Комментарии (4) RSS

    • это вам не openxml с спредшитами, асцендингами и десцендингами
      Ответить
    • Народная примета: если в таблице 16 колонок - значит сегодня пятница.
      Ответить
    • IDisposable есть? Дай подержать.
      Чё значит нет, а если найду?
      Ответить

    Добавить комментарий