Пример #1
0
        public void Draw <T>(int sheetIndex, string sheetName, params T[] objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }
            var type    = typeof(T);
            var objAttr = type.GetCustomAttribute <NPOIObjectAttribute>() ?? new NPOIObjectAttribute();
            var sheet   = _workbook.GetSheet(sheetName);

            if (sheet == null)
            {
                sheet = _workbook.CreateSheet(sheetName);
            }
            else
            {
                _workbook.Remove(sheet);
                sheet = _workbook.CreateSheet(sheetName);
            }
            var drawings = GetColumnDrawings(type);

            DrawHeader(drawings, sheet, objAttr.HeaderRowIndex);
            for (int i = 0; i < objects.Length; i++)
            {
                var obj = objects[i];
                DrawRow(drawings, sheet, objAttr.StartIndex + i, obj);
            }
        }