【问题标题】:border issue when export to pdf导出为pdf时的边框问题
【发布时间】:2020-01-18 02:03:39
【问题描述】:

版本:

PHP版本:7.0.8

Laravel 版本:5.6

包版本:2.1.0

说明:

您好,我们已经尝试使用 Laravel-Excel 通过 tcpdf 导出 pdf 文件功能, 但得到的边界问题是不同的。

你能教我们如何fix this issue

【问题讨论】:

  • wkhtmltopdf 更容易,实际上可以让你使用 css
  • 如果您不共享代码,我们如何解决您的问题?我们不是魔术师..

标签: php laravel tcpdf


【解决方案1】:

我使用过 tcpdf,也曾尝试使用 dompdf,但不适用于 php 7.1 或更高版本。

以下是我的代码:

public function exporttasklist(Request $request, Job $job) {

    $pathToFile = storage_path('app/xls/task.xlsx'); // find the xltx file

    Excel::load($pathToFile, function ($doc) use ($job) {

        $tasks = Task::where('job_id', $job->id)
            ->orderBy('created_at', 'DESC')
            ->get();

        $Company = Company::where('id', $job->company_id)->first();


        $sheet = $doc->setActiveSheetIndex(0);  // access to sheet 1


        $sheet->setCellValue('C4', $job->JobNo);
        $sheet->setCellValue('C5', $job->JobName);
        $sheet->setCellValue('L4', $Company->CompanyName);
        $sheet->setCellValue('L5', $Company->CompanyChineseName);

        $sheet->getStyle('L5')->getFont()->setName('msungstdlight');
        $sheet->setCellValue('P4', $job->JobTranslationDirection);
        $sheet->setCellValue('P5', $job->JobTranslationTeam);
        $sheet->setCellValue('R5', $job->JobSales);


        $styleArray2 = array(
            'borders' => array(
                'top' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,

                ),'bottom' => array(
                    'style' => PHPExcel_Style_Border::BORDER_NONE,

                ),'left' => array(
                    'style' => PHPExcel_Style_Border::BORDER_NONE,

                ),'right' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,

                ),
            ),
        );
       $sheet->getStyle('A7')->applyFromArray($styleArray2)

        }

    })->export('pdf');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    相关资源
    最近更新 更多