在尝试从数据库导出数据时,我看到了一些垃圾值,而不是显示UTF-8字符的实际数据。我用Excel打开CSV,然后用 Maatwebsite / Laravel-Excel软件包导出csv。
这是我的控制器:
public function downloadExcel($type)
{
$data = Item::get()->toArray();
return Excel::create('solutionstuff_example', function($excel) use ($data) {
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=solutionstuff_example.csv');
$excel->sheet('mySheet', function($sheet) use ($data)
{
$sheet->fromArray($data);
});
})->download($type);
}
Run Code Online (Sandbox Code Playgroud)
这是它的快照:
如果有人遇到问题并知道如何解决它,希望您能帮助我解决问题。谢谢
By using Maatwebsite/Laravel-Excel version 3.1 to import excel sheet, here I faced an issue date time column of the excel sheet returns unknown number. How to solve this? Example : Consider Cell value "29/07/1989" and returns as "32178" when import.
我正在尝试使用 Maatwebsite\Excel 包将新用户导入系统。默认包关注 ToModel 不适合我,因为我需要为每个导入的用户分配默认角色并为他/她发送电子邮件。我正在尝试使用 ToCollection 关注点,正如本文档页面最后一章中所述: https: //docs.laravel-excel.com/3.1/imports/validation.html。问题是我无法正确验证 Excel 文件的内容:错误消息根本不出现。当我使用 Maatwebsite\Excel 包及其 ToCollection 问题时,如何正确验证 Excel 文件的内容?
也许您知道如何为用户设置角色并在导入每个用户后发送电子邮件的不同方法吗?
<?php
/* My controller and action which calls import of users: */
/* used namespaces go here */
class ProfileController extends Controller
{
public function updateClient(UserClientRequest $request)
{
/* Client entity is being updated here, instead of this comment */
// here I try to import users from *.xls file:
$errors = [];
if ($request->hasFile('file_to_import_users')) {
$usersImport = new UsersImport($client->id);
$usersImport->import($request->file('file_to_import_users')); …Run Code Online (Sandbox Code Playgroud) 大家好,
我正在使用Laravel Excel/Maatwebsite开发一个系统。我想要实现的是,当用户将 Excel 文件插入系统时,系统将检查一些内容,然后将数据插入数据库。
这是数据库模式的一个实例:
Hadees:
h_id | h_english | r_id | h_last_raavi_id | b_id | s_id | k_id | h_status
Raavi:
r_id | r_english | r_status
Baab:
b_id | b_english | s_id | b_status
Section:
s_id | s_english | k_id | s_status
Kitaab:
k_id | k_english | k_status
Run Code Online (Sandbox Code Playgroud)
我的控制器:
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Section;
use App\Models\Raavi;
use App\Imports\HadeesImport;
use Excel;
class ImportHadeesController extends Controller{
/**
* Show the application import-hadees page.
*
* @return \Illuminate\Http\Response
*/ …Run Code Online (Sandbox Code Playgroud) 我正在使用 laravel maatwebsite excel,
我尝试传递变量并执行一些操作并作为数组返回以导出,
因此,当我尝试将数组传递给主控制器以进行 excel 导出(下载)时出现错误
我的主控制器
public function excel_export(Request $request){
return Excel::download(new UsersExport($request->exp_vlas), 'users.xlsx');
}
Run Code Online (Sandbox Code Playgroud)
这里我将变量传递给集合
我的出口控制器
public function collection(){
$instruments = implode(",",$this->id);
$instruments = explode(",",$instruments);
//$i=0;
foreach ($instruments as $instrument) {
$instr_list = DB::table('instruments')->select('*')->where('id',$instrument)->get()->toArray();
$arr_instrulist[] = $instr_list;
$instrument_var[] = $instrument;
$instr_list = "";
//$i++;
}
$arr_instrulist_excel[] = array('Instrument Name', 'Serial', 'Qa id', 'Unit', 'Range');
foreach($arr_instrulist as $arr_instrulists){
//$arr_instrulists = array($arr_instrulists);
$arr_instrulist_excel[] = array(
'Instrument Name' => $arr_instrulists[0]->instrument_name,
'Serial' => $arr_instrulists[0]->serial,
'Qa id' => $arr_instrulists[0]->qa_identification_no,
'Unit' => …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Maatwebsites 将我的报告导出到我的 Laravel 5.8 项目中:
在 Laravel-5.8 中,我尝试使用 Maatwebsite 导出到 Excel:
<?php
namespace App\Exports;
use App\User;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\FromView;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMapping;
use \Maatwebsite\Excel\Sheet;
use Maatwebsite\Excel\Concerns\RegistersEventListeners;
use Illuminate\Support\Facades\DB;
use Auth;
class EmployeesGoalPublishedExport implements FromCollection, ShouldAutoSize, WithHeadings
{
private $headings = [
'Staff ID',
'Name',
'Gender',
'Official Email',
'Department',
'HOD',
'HRBP',
'Line Manager',
'Goal …Run Code Online (Sandbox Code Playgroud) 我正在使用Maatwebsite 的 Laravel-Excel导入包含两张表的 Excel 文件。该文件是由另一个系统生成的;我无法改变它的制作方式。
在第一张纸上,第一行是列标题。这很好用。
...但第二张纸有两行不需要的文本,然后是第三行的标题。
我可以设置config(['excel.import.startRow' => 3])从第三行开始导入,但这意味着我错过了第一张表中的前两行有用数据。
config(['excel.import.startRow' => 3]);
$sheets = $import->all();
Run Code Online (Sandbox Code Playgroud)
有什么办法可以将excel.import.startRow第一张纸设置为 1,而将excel.import.startRow另一张纸设置为 3 吗?
我想使用 laravel-excel.maatwebsitelibrary 创建下载 excel 功能。我的代码如下:
return Excel::download(new PembukuanExport, 'pembukuan.xlsx');
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它给了我这样的错误
无法打开 /var/folders/n_/xh_10hm50dvbwg23cfq_kw3h0000gn/T/laravel-excel-DMBN3reNUrSiamYT 进行写入。
我的笔记本电脑是 macbook,一直在谷歌搜索但找不到正确的答案
我创建了一个 maatwebsite/excel 导入例程,我想测试它。
maatwebsite/excel 测试页面除了伪造之外没有向我提供任何其他信息。但我需要上传我的真实 Excel 文件,因为我想验证 Excel 文件中的数据是否已正确处理。
这是我的上传输入字段和用于点击端点的相应按钮/import
<form action="/import" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<input type="file" class="form-control-file file-path" name="fileToUpload">
</div>
<button type="submit" class="btn btn-primary">Import File</button>
</form>
Run Code Online (Sandbox Code Playgroud)
在视图的控制器端,将处理并导入上传的文件。
...
public function store(Request $request) {
$request->validate([
'fileToUpload' => 'required|file|max:4096|mimes:xls,xlsx',
]);
// start the import
Excel::import(new SheetNavigator, request()->file('fileToUpload'));
...
Run Code Online (Sandbox Code Playgroud)
需要导入的文件位于我的测试环境中:
/tests
/files
/myexcel.xlsx
Run Code Online (Sandbox Code Playgroud)
public function test_user_can_import_file() {
Excel::fake();
$datafile = new UploadedFile(
base_path('tests/files/myfile.xlsx'),
'myfile.xlsx',
'xlsx',
13071,
true);
$res = $this->post('/import', [
'fileToUpload' => $datafile
]);
// asserting, that everything …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Laravel,VueJS和上构建和应用程序inertiajs。
我正在使用maatwebsite/excel将我的数据导出为 excel 格式。
我有一个普通HTML形式的 vue 组件
家.vue
<form action="/project-profile" target="_blank" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" :value="csrf.content" />
<input type="hidden" name="slug" :value="JSON.stringify(generalDetails.slug)" />
<button class="font-medium tracking-wide">Download Profile</button>
</form>
Run Code Online (Sandbox Code Playgroud)
在安装方法上,我只是放置我的csrf令牌。
mounted() {
this.csrf = document.head.querySelector('meta[name="csrf-token"]');
}
Run Code Online (Sandbox Code Playgroud)
在Laravel某种程度上,我在web.php文件中做了一条路线
Route::post('project-profile','ProjectProfileExportController@ProjectProfile');
Run Code Online (Sandbox Code Playgroud)
每当我尝试导出或提交表单时,我都会page expired出错,我遵循了一些指南,它说存在问题,csrf_token但是在检查表单时我可以看到token放置得当。
我尝试通过将其作为 api 来做同样的事情api.php:
Route::post('project-profile', 'ProjectProfileExportController@ProjectProfile');
Run Code Online (Sandbox Code Playgroud)
但是这件事也没有按预期工作。
欢迎任何更好的方法。谢谢。
在laravel中,我发现了: View,但我无法完全理解它。
<?php
namespace App\Exports;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class Export implements FromView
{
/**
* @return \Illuminate\Support\View
*/
public function view(): View
{
return User::all();
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以解释,那么将不胜感激。