Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
1b74a3e2
Commit
1b74a3e2
authored
Jul 05, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
11111
parent
c22c784d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
190 additions
and
6 deletions
+190
-6
Edu.Common.csproj
Edu.Common/Edu.Common.csproj
+6
-0
AsposeCellHelper.cs
Edu.Common/Plugin/AsposeCellHelper.cs
+175
-0
ScrollController.cs
Edu.WebApi/Controllers/Course/ScrollController.cs
+9
-6
No files found.
Edu.Common/Edu.Common.csproj
View file @
1b74a3e2
...
...
@@ -19,4 +19,10 @@
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Aspose.Cells">
<HintPath>..\lib\Aspose.Cells.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Edu.Common/Plugin/AsposeCellHelper.cs
0 → 100644
View file @
1b74a3e2
using
Aspose.Cells
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Text
;
namespace
Edu.Common.Plugin
{
/// <summary>
/// Aspose.Cell帮助类
/// </summary>
public
class
AsposeCellHelper
{
/// <summary>
/// 模板导出
/// </summary>
/// <param name="list">模板数据</param>
/// <param name="isTempLate">是否模板导出</param>
/// <param name="tempLatePath">模板文件路劲</param>
public
static
byte
[]
ToExcelExtend
(
List
<
ExcelDataSource
>
list
,
bool
isTempLate
=
false
,
string
tempLatePath
=
""
)
{
Workbook
workbook
=
null
;
Worksheet
sheet
;
if
(
isTempLate
&&
!
string
.
IsNullOrEmpty
(
tempLatePath
.
Trim
()))
{
using
(
FileStream
file
=
new
FileStream
(
tempLatePath
,
FileMode
.
Open
,
FileAccess
.
Read
))
{
//将文件流中模板加载到工作簿对象中
workbook
=
new
Workbook
(
file
);
}
sheet
=
workbook
.
Worksheets
[
0
];
}
else
{
workbook
=
new
Workbook
();
sheet
=
workbook
.
Worksheets
[
0
];
}
int
rowIndex
=
0
;
Cells
cells
=
sheet
.
Cells
;
//生成行
foreach
(
var
item
in
list
)
{
int
columnsIndex
=
0
;
//设置行高
if
(
item
.
ColumnHight
>
0
)
{
cells
.
SetRowHeight
(
rowIndex
,
item
.
ColumnHight
);
}
else
{
cells
.
SetRowHeight
(
rowIndex
,
25
);
}
//生成列
foreach
(
var
subItem
in
item
.
ExcelRows
)
{
Style
style
=
cells
[
rowIndex
,
columnsIndex
].
GetStyle
();
//自动换行
style
.
IsTextWrapped
=
true
;
//设置单元宽度
if
(
subItem
.
CellWidth
>
0
)
{
cells
.
SetColumnWidth
(
columnsIndex
,
subItem
.
CellWidth
);
}
string
cellValue
=
subItem
.
Value
??
""
;
//设置单元格背景颜色
switch
(
subItem
.
BgColorEnum
)
{
case
ColorEnum
.
BrightGreen
:
style
.
ForegroundColor
=
Color
.
DodgerBlue
;
//fCellStyle.FillPattern = FillPattern.SolidForeground;
break
;
case
ColorEnum
.
DarkBlue
:
style
.
ForegroundColor
=
Color
.
DarkBlue
;
//fCellStyle.FillPattern = FillPattern.SolidForeground;
break
;
case
ColorEnum
.
Red
:
style
.
ForegroundColor
=
Color
.
Red
;
//fCellStyle.FillPattern = FillPattern.SolidForeground;
break
;
}
////字体大小
//if (subItem.FontHeight > 0)
//{
// style.Font.Size = subItem.FontHeight * 20;
//}
//else
//{
// style.Font.Size = 11 * 20;
//}
//字体
if
(!
string
.
IsNullOrWhiteSpace
(
subItem
.
FontName
))
{
style
.
Font
.
Name
=
subItem
.
FontName
;
}
else
{
style
.
Font
.
Name
=
"宋体"
;
}
if
(
subItem
.
FontSize
>
0
)
{
style
.
Font
.
Size
=
subItem
.
FontSize
;
}
// 设置字体颜色
switch
(
subItem
.
FontColorEnum
)
{
case
ColorEnum
.
Red
:
style
.
Font
.
Color
=
Color
.
Red
;
break
;
case
ColorEnum
.
Green
:
style
.
Font
.
Color
=
Color
.
Green
;
break
;
case
ColorEnum
.
DarkBlue
:
style
.
Font
.
Color
=
Color
.
DarkBlue
;
break
;
default
:
style
.
Font
.
Color
=
Color
.
Black
;
break
;
}
//字体加粗
if
(
subItem
.
IsBold
)
{
style
.
Font
.
IsBold
=
subItem
.
IsBold
;
}
//水平对齐方式
style
.
HorizontalAlignment
=
subItem
.
HAlignmentEnum
switch
{
HAlignmentEnum
.
CENTER
=>
TextAlignmentType
.
Center
,
HAlignmentEnum
.
LEFT
=>
TextAlignmentType
.
Left
,
HAlignmentEnum
.
RIGHT
=>
TextAlignmentType
.
Right
,
_
=>
TextAlignmentType
.
Center
,
};
//垂直对齐方式
style
.
VerticalAlignment
=
subItem
.
VAlignmentEnum
switch
{
VAlignmentEnum
.
CENTER
=>
TextAlignmentType
.
Center
,
VAlignmentEnum
.
TOP
=>
TextAlignmentType
.
Top
,
VAlignmentEnum
.
BOTTOM
=>
TextAlignmentType
.
Bottom
,
_
=>
TextAlignmentType
.
Center
,
};
if
(!
subItem
.
IsSetBorder
)
{
style
.
SetBorder
(
BorderType
.
BottomBorder
,
CellBorderType
.
Thin
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
LeftBorder
,
CellBorderType
.
Thin
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
RightBorder
,
CellBorderType
.
Thin
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
TopBorder
,
CellBorderType
.
Thin
,
Color
.
Black
);
}
else
{
style
.
SetBorder
(
BorderType
.
BottomBorder
,
CellBorderType
.
None
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
LeftBorder
,
CellBorderType
.
None
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
RightBorder
,
CellBorderType
.
None
,
Color
.
Black
);
style
.
SetBorder
(
BorderType
.
TopBorder
,
CellBorderType
.
None
,
Color
.
Black
);
}
cells
[
rowIndex
,
columnsIndex
].
SetStyle
(
style
);
cells
[
rowIndex
,
columnsIndex
].
PutValue
(
cellValue
);
columnsIndex
++;
}
rowIndex
++;
}
using
MemoryStream
ms
=
workbook
.
SaveToStream
();
ms
.
Flush
();
ms
.
Position
=
0
;
return
ms
.
ToArray
();
}
}
}
Edu.WebApi/Controllers/Course/ScrollController.cs
View file @
1b74a3e2
...
...
@@ -1179,11 +1179,11 @@ namespace Edu.WebApi.Controllers.Course
{
ExcelRows
=
new
List
<
ExcelColumn
>()
};
firstRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
"报名课程"
));
firstRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
"报名课程"
)
{
CellWidth
=
15
}
);
foreach
(
var
item
in
list
)
{
JObject
jobj
=
JObject
.
Parse
(
Common
.
Plugin
.
JsonHelper
.
Serialize
(
item
));
firstRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
jobj
.
GetStringValue
(
"CourseName"
)));
firstRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
jobj
.
GetStringValue
(
"CourseName"
))
{
CellWidth
=
15
}
);
}
slist
.
Add
(
firstRow
);
...
...
@@ -1222,6 +1222,7 @@ namespace Edu.WebApi.Controllers.Course
{
var
item
=
JObject
.
Parse
(
JsonHelper
.
Serialize
(
list
[
j
]));
var
ChapterList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
object
>>(
item
.
GetStringValue
(
"ChapterList"
));
string
str
=
""
;
if
(
ChapterList
!=
null
&&
i
<=
ChapterList
.
Count
-
1
)
{
var
sObj
=
JObject
.
Parse
(
ChapterList
[
i
].
ToString
());
;
...
...
@@ -1229,21 +1230,23 @@ namespace Edu.WebApi.Controllers.Course
int
State
=
sObj
.
GetInt
(
"State"
);
if
(
State
==
4
)
{
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
chapterName
)
{
}
);
str
=
"【缺课】\r\n"
+
chapterName
;
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
str
)
{
FontColorEnum
=
ColorEnum
.
Red
});
}
else
{
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
"【已上课】"
+
chapterName
));
str
=
"【已上课】\r\n"
+
chapterName
;
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
str
)
{
FontColorEnum
=
ColorEnum
.
DarkBlue
});
}
}
else
{
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
""
)
);
dataRow
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
str
)
);
}
};
slist
.
Add
(
dataRow
);
}
var
byteData
=
ExcelTempLate
Helper
.
ToExcelExtend
(
slist
);
var
byteData
=
AsposeCell
Helper
.
ToExcelExtend
(
slist
);
return
File
(
byteData
,
"application/octet-stream"
,
excelName
);
}
catch
(
Exception
ex
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment