Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
LaMartin-Webomagic
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Deep Dey
LaMartin-Webomagic
Commits
eba729f3
Commit
eba729f3
authored
Sep 25, 2024
by
Deep Dey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add api to download master-admission excel
parent
f0c352c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
34 deletions
+100
-34
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
...aMartin/admission/controller/AdmissionFormController.java
+54
-34
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/controller/AdmissionFormDAOController.java
.../admission/dao/controller/AdmissionFormDAOController.java
+46
-0
No files found.
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
View file @
eba729f3
...
...
@@ -447,39 +447,6 @@ public class AdmissionFormController {
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=master-interaction-template.pdf"
);
IOUtils
.
copy
(
pdfStream
,
response
.
getOutputStream
());
}
public
byte
[]
convertAdmissionFormToExcel
(
List
<
AdmissionFormData
>
admissionFormDataList
)
throws
Exception
{
Workbook
workbook
=
new
HSSFWorkbook
();
Sheet
sheet
=
workbook
.
createSheet
(
"Admission Form Data"
);
Row
headerRow
=
sheet
.
createRow
(
0
);
headerRow
.
createCell
(
0
).
setCellValue
(
"SL. NO."
);
headerRow
.
createCell
(
1
).
setCellValue
(
"Reference Id"
);
headerRow
.
createCell
(
2
).
setCellValue
(
"Name"
);
headerRow
.
createCell
(
3
).
setCellValue
(
"Father's Name"
);
headerRow
.
createCell
(
4
).
setCellValue
(
"Interaction Time"
);
// Start data rows from second row
int
rowIndex
=
1
;
for
(
AdmissionFormData
admissionFormData
:
admissionFormDataList
)
{
Row
dataRow
=
sheet
.
createRow
(
rowIndex
++);
// Set data for each column based on AdmissionFormData fields
dataRow
.
createCell
(
0
).
setCellValue
(
admissionFormData
.
getId
());
dataRow
.
createCell
(
1
).
setCellValue
(
admissionFormData
.
getFatherEmail
());
dataRow
.
createCell
(
2
).
setCellValue
(
admissionFormData
.
getFullName
());
dataRow
.
createCell
(
3
).
setCellValue
(
admissionFormData
.
getFatherName
());
dataRow
.
createCell
(
4
).
setCellValue
(
admissionFormData
.
getInteractionTime
());
}
// Write the workbook to a byte array
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
workbook
.
write
(
out
);
return
out
.
toByteArray
();
}
@GetMapping
(
value
=
"/admission-form/download-master-interaction-excel"
...
...
@@ -513,7 +480,11 @@ public class AdmissionFormController {
}
// Call the convertAdmissionFormToExcel method to get the Excel data as byte array
byte
[]
excelData
=
convertAdmissionFormToExcel
(
admissionFormDataList
);
byte
[]
excelData
=
this
.
admissionFormDAOController
.
convertAdmissionFormToExcel
(
admissionFormDataList
,
false
);
// Set response content type as application/vnd.ms-excel
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
+
"; charset=UTF-8"
);
...
...
@@ -570,6 +541,55 @@ public class AdmissionFormController {
}
@GetMapping
(
value
=
"/admission-form/download-master-admission-excel"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"SUCCESS"
),
@ApiResponse
(
code
=
400
,
message
=
"FAILED"
),
@ApiResponse
(
code
=
500
,
message
=
"Exception Occurred"
)
})
@ApiOperation
(
value
=
""
)
public
void
downloadMasterAdmissionExcel
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
"apikey"
)
String
apiKey
,
@RequestParam
String
schoolName
,
@RequestParam
String
admissionDate
)
throws
Exception
{
List
<
AdmissionFormData
>
admissionFormDataList
=
this
.
admissionFormDAOController
.
getAdmissionFormDataList
(
schoolName
,
null
,
null
,
null
,
null
,
admissionDate
);
if
(
admissionFormDataList
.
isEmpty
())
{
throw
new
Exception
(
"No Admission Data Found"
);
}
// Call the convertAdmissionFormToExcel method to get the Excel data as byte array
byte
[]
excelData
=
this
.
admissionFormDAOController
.
convertAdmissionFormToExcel
(
admissionFormDataList
,
true
);
// Set response content type as application/vnd.ms-excel
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
+
"; charset=UTF-8"
);
// Set a downloadable filename
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"master-admission-excel.xls\""
);
// Write the Excel data to the response output stream
response
.
getOutputStream
().
write
(
excelData
);
}
@GetMapping
(
value
=
"/admission-form/count"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
...
...
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/controller/AdmissionFormDAOController.java
View file @
eba729f3
...
...
@@ -10,11 +10,16 @@ import com.example.LaMartin.common.service.PdfService;
import
com.example.LaMartin.common.service.TemplateService
;
import
com.example.LaMartin.config.Settings
;
import
lombok.AllArgsConstructor
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.jetbrains.annotations.NotNull
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.List
;
import
java.util.Objects
;
...
...
@@ -201,4 +206,45 @@ public class AdmissionFormDAOController {
return
admissionFormDataRepository
.
getAdmissionFormCount
();
}
public
byte
[]
convertAdmissionFormToExcel
(
List
<
AdmissionFormData
>
admissionFormDataList
,
boolean
showAdmission
)
throws
Exception
{
Workbook
workbook
=
new
HSSFWorkbook
();
Sheet
sheet
=
workbook
.
createSheet
(
"Admission Form Data"
);
Row
headerRow
=
sheet
.
createRow
(
0
);
headerRow
.
createCell
(
0
).
setCellValue
(
"SL. NO."
);
headerRow
.
createCell
(
1
).
setCellValue
(
"Reference Id"
);
headerRow
.
createCell
(
2
).
setCellValue
(
"Name"
);
headerRow
.
createCell
(
3
).
setCellValue
(
"Father's Name"
);
if
(
showAdmission
)
{
headerRow
.
createCell
(
4
).
setCellValue
(
"Admission Time"
);
}
else
{
headerRow
.
createCell
(
4
).
setCellValue
(
"Interaction Time"
);
}
// Start data rows from second row
int
rowIndex
=
1
;
for
(
AdmissionFormData
admissionFormData
:
admissionFormDataList
)
{
Row
dataRow
=
sheet
.
createRow
(
rowIndex
++);
// Set data for each column based on AdmissionFormData fields
dataRow
.
createCell
(
0
).
setCellValue
(
admissionFormData
.
getId
());
dataRow
.
createCell
(
1
).
setCellValue
(
admissionFormData
.
getFatherEmail
());
dataRow
.
createCell
(
2
).
setCellValue
(
admissionFormData
.
getFullName
());
dataRow
.
createCell
(
3
).
setCellValue
(
admissionFormData
.
getFatherName
());
if
(
showAdmission
)
{
dataRow
.
createCell
(
4
).
setCellValue
(
admissionFormData
.
getAdmissionTime
());
}
else
{
dataRow
.
createCell
(
4
).
setCellValue
(
admissionFormData
.
getInteractionTime
());
}
}
// Write the workbook to a byte array
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
workbook
.
write
(
out
);
return
out
.
toByteArray
();
}
}
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