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
Pratik Shrivastava
LaMartin-Webomagic
Commits
ae4f4a7e
Commit
ae4f4a7e
authored
Jul 11, 2024
by
Pratik Shrivastava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add 'download-master-interaction-excel' feature
parent
cb00966a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
20 deletions
+54
-20
lamartinBackend/pom.xml
lamartinBackend/pom.xml
+5
-0
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
...aMartin/admission/controller/AdmissionFormController.java
+49
-20
No files found.
lamartinBackend/pom.xml
View file @
ae4f4a7e
...
@@ -153,6 +153,11 @@
...
@@ -153,6 +153,11 @@
<groupId>
javax.mail
</groupId>
<groupId>
javax.mail
</groupId>
<artifactId>
javax.mail-api
</artifactId>
<artifactId>
javax.mail-api
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
4.1.1
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
View file @
ae4f4a7e
...
@@ -17,11 +17,14 @@ import org.springframework.http.MediaType;
...
@@ -17,11 +17,14 @@ import org.springframework.http.MediaType;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -316,6 +319,38 @@ public class AdmissionFormController {
...
@@ -316,6 +319,38 @@ public class AdmissionFormController {
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=master-interaction-template.pdf"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=master-interaction-template.pdf"
);
IOUtils
.
copy
(
pdfStream
,
response
.
getOutputStream
());
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
(
@GetMapping
(
...
@@ -327,7 +362,7 @@ public class AdmissionFormController {
...
@@ -327,7 +362,7 @@ public class AdmissionFormController {
@ApiResponse
(
code
=
500
,
message
=
"Exception Occurred"
)
@ApiResponse
(
code
=
500
,
message
=
"Exception Occurred"
)
})
})
@ApiOperation
(
value
=
""
)
@ApiOperation
(
value
=
""
)
public
Object
downloadMasterInteractionExcel
(
public
void
downloadMasterInteractionExcel
(
HttpServletRequest
request
,
HttpServletRequest
request
,
HttpServletResponse
response
,
HttpServletResponse
response
,
@RequestParam
(
"apikey"
)
String
apiKey
,
@RequestParam
(
"apikey"
)
String
apiKey
,
...
@@ -347,25 +382,19 @@ public class AdmissionFormController {
...
@@ -347,25 +382,19 @@ public class AdmissionFormController {
if
(
admissionFormDataList
.
isEmpty
())
{
if
(
admissionFormDataList
.
isEmpty
())
{
throw
new
Exception
(
"No Admission Data Found"
);
throw
new
Exception
(
"No Admission Data Found"
);
}
}
//TODO: write logic to download excel
// Call the convertAdmissionFormToExcel method to get the Excel data as byte array
return
new
ResponseEntity
<>(
byte
[]
excelData
=
convertAdmissionFormToExcel
(
admissionFormDataList
);
new
GeneralResponse
(
true
,
// Set response content type as application/vnd.ms-excel
AppConstants
.
RESPONSE_SUCCESS_STATUS_CODE
,
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
+
"; charset=UTF-8"
);
"Excel should be downloaded"
,
null
// Set a downloadable filename
),
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\"master-interaction-excel.xls\""
);
HttpStatus
.
OK
);
// Write the Excel data to the response output stream
// String output = templateService
response
.
getOutputStream
().
write
(
excelData
);
// .generateMasterInteractionTemplate(admissionFormDataList);
//
// ByteArrayInputStream pdfStream = pdfService.convertHtmlToPdf(output);
//
// response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
// response.setHeader("Content-Disposition", "attachment; filename=master-interaction-template.pdf");
// IOUtils.copy(pdfStream, response.getOutputStream());
}
}
@GetMapping
(
@GetMapping
(
...
...
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