We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func (h *BookingMuseumHandler) DownloadExcels(c echo.Context) error {
data, _, err := h.bookingUcase.Fetch(ctx, au, ¶ms) if err != nil { return err } // Prepare the response data pubRes := []domain.ListBookingMuseumDataResponse{} for _, row := range data { res := domain.ListBookingMuseumDataResponse{ ID: row.ID, Nama: row.PengunjungBookings.Nama, Email: row.PengunjungBookings.Email, Kategori: row.KategoriBookings.Nama, Sesi: row.SesiBookings.Nama, JumlahPengunjung: row.JumlahPengunjung, TanggalBerkunjung: row.TanggalBerkunjung, Dokumen: row.DocBookings.Doc, BuktiBayarBookings: row.BuktiBayarBookings.Bukti, Status: row.Status, } pubRes = append(pubRes, res) } // Create a new Excel file f := excelize.NewFile() index, err := f.NewSheet("Booking Museum") if err != nil { return err } f.SetActiveSheet(index) // Simpan file sementara di server untuk debugging // Set header headers := []string{ "ID", "Nama", "Email", "Kategori", "Sesi", "Jumlah Pengunjung", "Tanggal Berkunjung", "Dokumen", "Bukti Bayar", "Status", } for col, header := range headers { f.SetCellValue("Booking Museum", fmt.Sprintf("%s1", string('A'+col)), header) } // Write data to Excel file for i, res := range pubRes { f.SetCellValue("Booking Museum", fmt.Sprintf("A%d", i+2), strconv.FormatInt(res.ID, 10)) f.SetCellValue("Booking Museum", fmt.Sprintf("B%d", i+2), res.Nama) f.SetCellValue("Booking Museum", fmt.Sprintf("C%d", i+2), res.Email) f.SetCellValue("Booking Museum", fmt.Sprintf("D%d", i+2), res.Kategori) f.SetCellValue("Booking Museum", fmt.Sprintf("E%d", i+2), res.Sesi) f.SetCellValue("Booking Museum", fmt.Sprintf("F%d", i+2), strconv.FormatInt(res.JumlahPengunjung, 10)) f.SetCellValue("Booking Museum", fmt.Sprintf("G%d", i+2), res.TanggalBerkunjung) f.SetCellValue("Booking Museum", fmt.Sprintf("H%d", i+2), res.Dokumen) f.SetCellValue("Booking Museum", fmt.Sprintf("I%d", i+2), res.BuktiBayarBookings) f.SetCellValue("Booking Museum", fmt.Sprintf("J%d", i+2), res.Status) } if err := f.SaveAs("temp_booking_museum.xlsx"); err != nil { return err } buf := new(bytes.Buffer) if err := f.Write(buf); err != nil { return c.JSON(500, "Failed to write Excel data to memory") } // Debugging: Periksa ukuran buffer fmt.Println("Buffer size:", buf.Len()) // Pastikan ukuran file lebih besar dari 0 fmt.Printf("File size before sending: %d bytes\n", len(buf.Bytes())) // Pastikan kita mengirimkan data dalam bentuk binary (Blob) c.Response().Header().Set("Content-Disposition", "attachment; filename=booking_data.xlsx") c.Response().Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") c.Response().Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate") c.Response().Header().Set("Pragma", "no-cache") c.Response().Header().Set("Transfer-Encoding", "chunked") // Kirimkan data dalam bentuk byte array (Blob) return c.Blob(200, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", buf.Bytes()) } echo/v4 v4.11.3 excelize/v2 v2.9.0 hasil dari pemanggilan api
The text was updated successfully, but these errors were encountered:
Thanks for your issue. Could you show us a complete, standalone example program or reproducible demo with main function?
Sorry, something went wrong.
No branches or pull requests
func (h *BookingMuseumHandler) DownloadExcels(c echo.Context) error {
The text was updated successfully, but these errors were encountered: