问题描述
我为货运标签设置了这种布局。 货运标签图片:
此布局填充了来自搜索结果的数据 Web结果WooCommerce以CSV下载
使用PHP,我可以从CSV中提取每一行,并为每个订单创建一个标签。
我尝试使用 Ctrl + P 打印,但这不起作用
如何直接打印到打印机或为每个表格创建图像并自动打印它们?
这是我的代码
订购CSV数据(PHP)
$orders = array();
$neworders=array();
$h = fopen("orders.csv","r");
$header = fgetcsv($h);
while (($data = fgetcsv($h,1000,",")) !== FALSE){
$orders[] = array_combine($header,$data);
}
fclose($h);
$z=0;
$flag=false;
for($i=0;$i<sizeof($orders);$i++){
if(sizeof($neworders)>0){
for($x=0;$x<sizeof($neworders);$x++){
if($neworders[$x]['Order ID']==$orders[$i]['Order ID']){
$neworders[$x]['Product ID'][]=$orders[$i]['Product ID'];
$neworders[$x]['Product SKU'][]=$orders[$i]['Product SKU'];
$neworders[$x]['Product Name'][]=$orders[$i]['Product Name'];
$neworders[$x]['Quantity of items purchased'][]=$orders[$i]['Quantity of items purchased'];
$neworders[$x]['All Line Metadata'][]=$orders[$i]['All Line Metadata'];
$flag=true;
break;
}
}
if($flag==false){
$neworders[$z]['Order ID']=$orders[$i]['Order ID'];
$neworders[$z]['Order Date']=$orders[$i]['Order Date'];
$neworders[$z]['Order Status']=$orders[$i]['Order Status'];
$neworders[$z]['Shipping RUT']=$orders[$i]['Shipping RUT'];
$neworders[$z]['Shipping First Name']=$orders[$i]['Shipping First Name'];
$neworders[$z]['Shipping Last Name']=$orders[$i]['Shipping Last Name'];
$neworders[$z]['Shipping Method Title']=$orders[$i]['Shipping Method Title'];
$neworders[$z]['Shipping Country']=$orders[$i]['Shipping Country'];
$neworders[$z]['Shipping State']=$orders[$i]['Shipping State'];
$neworders[$z]['Shipping City']=$orders[$i]['Shipping City'];
$neworders[$z]['Shipping Address Line 1']=$orders[$i]['Shipping Address Line 1'];
$neworders[$z]['Shipping Address Line 2']=$orders[$i]['Shipping Address Line 2'];
$neworders[$z]['Shipping Phone Number']=$orders[$i]['Shipping Phone Number'];
$neworders[$z]['Customer Note']=$orders[$i]['Customer Note'];
$neworders[$z]['Product ID'][]=$orders[$i]['Product ID'];
$neworders[$z]['Product SKU'][]=$orders[$i]['Product SKU'];
$neworders[$z]['Product Name'][]=$orders[$i]['Product Name'];
$neworders[$z]['Quantity of items purchased'][]=$orders[$i]['Quantity of items purchased'];
$neworders[$z]['All Line Metadata'][]=$orders[$i]['All Line Metadata'];
$z++;
}
}else{
$neworders[$z]['Order ID']=$orders[$i]['Order ID'];
$neworders[$z]['Order Date']=$orders[$i]['Order Date'];
$neworders[$z]['Order Status']=$orders[$i]['Order Status'];
$neworders[$z]['Shipping RUT']=$orders[$i]['Shipping RUT'];
$neworders[$z]['Shipping First Name']=$orders[$i]['Shipping First Name'];
$neworders[$z]['Shipping Last Name']=$orders[$i]['Shipping Last Name'];
$neworders[$z]['Shipping Method Title']=$orders[$i]['Shipping Method Title'];
$neworders[$z]['Shipping Country']=$orders[$i]['Shipping Country'];
$neworders[$z]['Shipping State']=$orders[$i]['Shipping State'];
$neworders[$z]['Shipping City']=$orders[$i]['Shipping City'];
$neworders[$z]['Shipping Address Line 1']=$orders[$i]['Shipping Address Line 1'];
$neworders[$z]['Shipping Address Line 2']=$orders[$i]['Shipping Address Line 2'];
$neworders[$z]['Shipping Phone Number']=$orders[$i]['Shipping Phone Number'];
$neworders[$z]['Customer Note']=$orders[$i]['Customer Note'];
$neworders[$z]['Product ID'][]=$orders[$i]['Product ID'];
$neworders[$z]['Product SKU'][]=$orders[$i]['Product SKU'];
$neworders[$z]['Product Name'][]=$orders[$i]['Product Name'];
$neworders[$z]['Quantity of items purchased'][]=$orders[$i]['Quantity of items purchased'];
$neworders[$z]['All Line Metadata'][]=$orders[$i]['All Line Metadata'];
$z++;
}
}
此后,我获取新订单并为每个订单创建一个HTML表。
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial,sans-serif;
border-collapse: collapse;
max-width:58mm;
max-heigth:90mm;
width:58mm;
heigth:90mm;
overflow:auto;
display:block;
}
td,th {
border: 1px solid #dddddd;
text-align: left;
padding: 3px;
font-size:12px;
}
</style>
</head>
<body>
<?php
for($i=0;$i<sizeof($neworders);$i++){
?>
<table id="myTable">
<tr>
<th colspan="2"><img width="100%" src="logo.png"/></th>
</tr>
<tr >
<td>RUT:</td>
<td><?php echo $neworders[$i]['Shipping RUT'];?></td>
</tr>
<tr>
<td colspan="2" style="font-size:12px"><?php echo ucfirst($neworders[$i]['Shipping First Name'])." ".ucfirst($neworders[$i]['Shipping Last Name']);?></td>
</tr>
<tr>
<td colspan="2" ><?php echo regiones($neworders[$i]['Shipping State'])."/".$neworders[$i]['Shipping City'];?></td>
</tr>
<tr>
<td colspan="2">Dirección:</td>
</tr>
<tr>
<td colspan="2">
<?php
echo $neworders[$i]['Shipping Address Line 1'];
if(strlen($neworders[$i]['Shipping Address Line 2'])>0){
echo " - ".$neworders[$i]['Shipping Address Line 2'];
}
if(strlen($neworders[$i]['Customer Note'])>0){
echo " (".$neworders[$i]['Customer Note'].")";
}
?></td>
</tr>
<tr>
<td>Teléfono:</td>
<td><?php echo $neworders[$i]['Shipping Phone Number'];?></td>
</tr>
<tr>
<td colspan="2" style="font-size:10px">
<?php
for($x=0;$x<sizeof($neworders[$i]['Product ID']);$x++){
echo "(".$neworders[$i]['Quantity of items purchased'][$x].") ";
echo $neworders[$i]['Product ID'][$x]."|";
echo $neworders[$i]['Product Name'][$x]."(";
echo explodepolera($neworders[$i]['All Line Metadata'][$x]).")</br>";
}
?>
</td>
</tr>
</table>
<br/>
<?php
}
?>
</body>
我尝试在此行之后为($ I = 0; $ I
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)