my Code Here is Exporting Images For Products Table but it exported in this format https://prnt.sc/109zsm6 i think image not setting for column value or not overriding
in column there is image and text from $product->image how should print image in right way
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
//Freeze frist row
$event->sheet->freezePane('A2', 'A2');
$products = Product::limit(10)->get();
//Set row height
for ($i = 0; $i < count($products); $i++) //iterate based on row count
{
$event->sheet->getRowDimension('E' . +$i)->setRowHeight(60);
}
$loop = 1;
foreach ($products as $product) {
$drawing = new Drawing();
$drawing->setName('image');
$drawing->setDescription('image');
$drawing->setPath(public_path($product->image));
$drawing->setHeight(70);
$drawing->setOffsetX(5);
$drawing->setOffsetY(5);
$drawing->setCoordinates('E' . $loop);
$drawing->setWorksheet($event->sheet->getDelegate());
$loop++;
}
},
];
}
/**
* #var product $product
*/
public function map($product): array
{
return [
$product->id,
$product->category_id,
$product->category_name,
$product->name,
$product->image,
$product->created_at,
$product->updated_at,
];
}
Related
After search the search result is displayed in the screen. That content I must download as excel.
Controller.php
public function searchList(Request $request)
{
$fleet_issues = FleetIssue::all();
$list = FleetIssue::orderBy('check_at', 'desc');
$directory = FleetManagementHelper :: getFleetIssueImageDirectory();
$fleet_issue_type = FleetIssueType::all();
$vehicle_class = VehicleClass::orderBy('id', 'asc')->get();
$location= Location::orderBy('id', 'asc')->get();
if( $request->plate_number){
$list = $list->where('plate_number', $request->plate_number );
}
if( $request->branch){
$list = $location->where('id', $request->branch );
}
if( $request->nric){
$list = $list->where('nric',$request->nric);
}
if( $request->fleet_issue_type_id){
$list = $list->where('fleet_issue_type_id',$request->fleet_issue_type_id);
}
$list = $list->paginate(20);
view('pages.control_panel.view_issues',compact('list','fleet_issues','directory','fleet_issue_type','vehicle_class','location'));
}
Below is to download the excel file from the Export.php
public function downloadExcel()
{
return Excel::download(new Export,'List.xlsx');
}
Below is the Export.php..How can i filter search here??
Export.php
Use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
class Export implements FromView,ShouldAutoSize,WithHeadings, WithEvents
{
public function headings(): array
{
return [
'Reservation Number', 'NRIC/Passport', 'Vehicle Model','Branch','Date of Checking','Issues'
];
}
public function view() : View
{
$vehicle_class = VehicleClass::orderBy('id', 'asc')->get();
$location= Location::orderBy('id', 'asc')->get();
$fleet_issue_type = FleetIssueType::orderBy('id', 'asc')->get();
$list = FleetIssue::orderBy('check_at', 'desc')->paginate(20);
$directory = FleetManagementHelper :: getFleetIssueImageDirectory();
if( $this->vehicle_model){
$list = $list->where('vehicle_model', $this->vehicle_model);
}
return view('pages.control_panel.fleet_management.fleet_issues.list_fleet_issues',compact('vehicle_class','location','fleet_issue_type','list','directory'));
}
How can i export my result from search to excel?How i can filter the searchlist in Export??How to passing current request variable in export like doing in the controller?
I want to remove strings starting with # or // from the lines array.
It is not working.
Here is the code (excluding the preliminaries like reading the file etc):
def file = new File("$_file").text.replaceAll("\\r\\n|\\r|\\n", " ");
String[] lines_ = file.split("\\s*;\\s*");
println(lines_);
for(line in lines_)
{
if(line.take(1) =='#' || line.take(2) == '//')
{
remove(lines_ , line);
}
}
Here is the remove function
public static String[] remove(String[] input, String deleteMe)
{
if (input != null) {
List<String> list = new ArrayList<String>(Arrays.asList(input));
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(deleteMe)) {
list.remove(i);
}
}
return list.toArray(new String[0]);
} else {
return new String[0];
}
}
Here is the $_file
canvas cvs {
width:100,
dfdf:60
}
;
//this is a comment;
#also a comment;
sprite ball{
body : hr,
Image: here
}
;
Thanks.
You can read the lines from the file with readLines(), then just call findAll like so:
String[] lines = new File("$_file")
.readLines()
.findAll { !it.startsWith('#') && !it.startsWith('//') }
I did it!
I changed remove function to:
static String[] remove(String[] str_array , String what){
List<String> list = new ArrayList<String>(Arrays.asList(str_array));
list.remove(what);
str_array = list.toArray(new String[0]);
return str_array;
}
and remove(lines_,line) to lines_ = remove(lines,line)
And its ok now!
i want to filter items from listbox when i typed in combobox ..
suppose, when i type "A" in combobox then listbox display items which contains "A" anywhere.. without using SQL STATEMENT...
below is my code..
private void FillListBoxes()
{
lbSearch.DisplayMember = "CatName";
lbSearch.ValueMember = "catID";
int count = FillList.Rows.Count;
if (count > 0)
{
lbSearch.Items.Clear();
for (int i = 0; i < count; i++)
{
lbSearch.Items.Add(FillList.Rows[i]["CatName"].ToString());
}
}
}
You need to hold a list with all the items, assume AllItems is the name of this list. then you can try:
private void FillListBoxes()
{
string check=combobox1.Text;
lbSearch.Items.Clear();
foreach (string item in AllItems)
{
if (item.Contains(check);
{
lbSearch.Items.Add(item);
}
}
}
if (chklistmembership.CheckedItems.Count > 0)
{
foreach (var checkedItem in this.chklistmembership.CheckedItems)
{
cmd.Parameters.AddWithValue("#membership",checkedItem.ToString() );
//chklistmembership.SelectedItem.ToString());
}
}
else
{
cmd.Parameters.AddWithValue("#membership", DBNull.Value);
}
This is not working, it can store only 1 checkeditem.
for ($i; i < $size; $i++)
{
$sql="INSERT INTO user_choice (user_id,prefrence_name) VALUES ('".$id."','".$checkbox1[$i]."')";
$result = mysqli_query($dbh, $sql);
}
use this one
I have a problem with my CakePhp Site.
My index is showing fine with pagination, but when I search the page, pagination is gone and the search results aren't showing (instead the index is showing without paging).
Any idea where my code is wrong?
class ItemsController extends AppController {
var $name = 'Items';
// load any helpers used in the views
var $helpers = array('Paginator', 'Html', 'Form', 'Javascript', 'Misc', 'Time', 'Tagcloud');
var $components = array('RequestHandler');
/**
* index()
* main index page for items
* url: /items/index
*/
function index() {
// get all options for form
$tags = $this->Item->Tag->find('list', array(
'fields'=>'id, name',
'order'=>'Tag.name',
'conditions'=> array(
'Tag.status'=>'1'
)
));
// add name to option
$tags = array(''=>'Tags') + $tags;
//pr($tags);
// if form submitted
if (!empty($this->data)) {
// if reset button pressed redirect to index page
if(isset($this->data['reset'])) {
$this->redirect(array('action'=>'index'));
}
// init
$url = '';
// remove search key if not set
if($this->data['search'] == '') {
unset($this->data['search']);
}
// loop through filters
foreach($this->data as $key=>$filter) {
// ignore submit button
if($key != 'filter') {
// init
$selected = '';
switch($key) {
case 'tag':
$selected = $tags[$filter];
break;
case 'search':
$selected = $filter;
break;
}
// if filter value is not empty
if(!empty($filter)) {
$selected = $this->slug($selected);
$url .= "/$key/$selected";
}
}
}
// redirect
$this->redirect('/items/index/'.$url);
} else {
// set form options
$this->data['tag'] = '';
$this->data['search'] = '';
}
// if any parameters have been passed
if(!empty($this->params['pass'])) {
// only select active items
$conditions = array('Item.status'=>1);
// get params
$params = $this->params['pass'];
// loop
foreach($params as $key=>$param) {
// get the filter value
if(isset($params[$key+1])) {
$value = $params[$key+1];
}
// switch on param
switch($param)
{
case 'tag':
// get tag
$tag = $this->Item->Tag->find('first', array(
'recursive' => 0,
'conditions' => array(
'Tag.slug'=>$value
)
));
// save value for form
$this->data['tag'] = $tag['Tag']['id'];
break;
case 'search':
// setup like clause
$conditions['Item.name LIKE'] = "%{$value}%";
// save search string for form
$this->data['search'] = str_replace('_', ' ', $value);
break;
}
}
//pr($conditions);
// get all items with param conditions
$items = $this->Item->find('all', array(
'order' => 'Item.name',
'conditions' => $conditions
));
// if tag filter has been set
if(isset($tag)) {
// loop through items
foreach($items as $key=>$item) {
// init
$found = FALSE;
// loop through tags
foreach($item['Tag'] as $k=>$g) {
// if the tag id matches the filter tag no need to continue
if($g['id'] == $tag['Tag']['id']) {
$found = TRUE;
break;
}
}
// if the tag was not found in items
if(!$found) {
// remove from list
unset($items[$key]);
}
}
}
} else {
// get all items from database where status = 1, order by name
$items = $this->Item->find('all', array(
'order' => 'Item.name',
'conditions' => array(
'Item.status'=>1
)
));
}
$this->paginate = array(
'limit' => 10
);
$data = $this->paginate('Item');
// set page title
$this->pageTitle = 'Index Page';
// set layout file
$this->layout = 'index';
// save the items in a variable for the view
$this->set(compact('data', 'tags', 'items'));
}
You'll want to pass your search conditions to the paginate functionality. You do this through the controller's paginate property.
function index() {
...
switch($param) {
...
case 'search':
$this->paginate['conditions']['Item.name LIKE'] = "%{$value}%";
More information on setting up pagination can be found here.