我正在开发一个项目,我们已经开始将项目移动到最终服务器进行生产。我们根本没有更改代码,但excel导出无法正常工作。当我们打开导出的文件时,它会出现“不可读的内容”错误。当我单击是以更正它时,将excel留空甚至没有显示空白电子表格。看看excel错误日志,我似乎找不到任何指向问题的东西。
我已经开始评论代码,一旦我注释掉从服务器获取数据并将它们放在excel文件中的行,文件就会正常工作。这再次在我们的DEV环境中运行良好,但我知道他们正在使用不同类型的服务器。
Dev Env - 使用apache web服务器的2008 SQL Server Prod Env - 使用apache web服务器的2012 SQL Server
以下是代码:
public function actionchecklistExport( $id )
{
$mastertracker = TblHarvestMasterTracker::model()->findByPk( $id );
$model=new TblHarvestExtractionChecklist('search');
$var_system_family = '';
if( isset( $mastertracker->attributes['system_family'] ) && !empty( $mastertracker->attributes['system_family'] ) )
$var_system_family = $mastertracker->attributes['system_family'];
require_once(Yii::app()->basePath."/extensions/Spreadsheet/Excel/Writer.php");
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8);
$worksheet =& $workbook->addWorksheet('Extraction Checklist');
$worksheet->setInputEncoding('UTF-8');
//$worksheet->setSheetstate_visible = 'visible';
// A BUNCH OF CODE TO SETUP LOOK OF SHEET.
$row_num=0;
$worksheet->write($row_num,0,"System Tracking #",$yellowHeader);
$worksheet->write($row_num,1,"Part Number",$yellowHeader);
$worksheet->write($row_num,2,"Description",$yellowHeader);
$worksheet->write($row_num,3,"System Model",$yellowHeader);
$worksheet->write($row_num,4,"Sub-System",$yellowHeader);
$worksheet->write($row_num,5,"Extraction Guidance",$yellowHeader);
$worksheet->write($row_num,6,"ICV",$yellowHeader);
$worksheet->write($row_num,7,"Specific Extraction",$yellowHeader);
$worksheet->write($row_num,8,"Product Locator(N/A/Yes/No)",$yellowHeader);
$worksheet->write($row_num,9,"Certified Component(N/A/Yes/No)",$yellowHeader);
$worksheet->write($row_num,10,"U Part Set Up Status",$yellowHeader);
$worksheet->write($row_num,11,"Part Level Test Document",$yellowHeader);
$worksheet->write($row_num,12,"Specific Packaging",$yellowHeader);
$worksheet->write($row_num,13,"Captured (Y/N)",$yellowHeader);
$worksheet->write($row_num,14,"IF Capture = N",$orangeHeader);
$worksheet->write($row_num,15,"If Alternate Part or Parent/Child List Part #",$orangeHeader);
$worksheet->write($row_num,16,"Alternate Part or Parent/Child Action",$orangeHeader);
$worksheet->write($row_num,17,"Extraction Comments",$orangeHeader);
$worksheet->write($row_num,18,"Part Level Test Result (Pass, Fail, N/A):",$greenHeader);
$worksheet->write($row_num,19,"Product Locator Printed(Yes, N/A)",$greenHeader);
$worksheet->write($row_num,20,"Visual Inspection / Labeling.(Pass, Fail, N/A)",$greenHeader);
$worksheet->write($row_num,21,"Part Acceptance (Pass, Fail, N/A):",$greenHeader);
$worksheet->write($row_num,22,"Part Acceptance Initials",$greenHeader);
$worksheet->write($row_num,23,"Unique ID",$yellowHeader);
$worksheet->write($row_num,24,"Date",$greenHeader);
$worksheet->write($row_num,25,"Disposition if Acceptance Fails",$yellowHeader);
$res=$model->search($id, false, false, $var_system_family)->getData();
$row_num=$row_num+1;
foreach($res as $key=>$val)
{
//if(!is_null($val['Part_Acceptance_Checklist_Approval_Date']) && $val['Part_Acceptance_Checklist_Approval_Date']!='' && $val['Part_Process_Status']=='Step 3: Awaiting PO')
//{
// $content_text = &$workbook->addFormat( array( 'fgcolor'=> '22','border'=>'1','Size' => '12', 'align'=>'center' ,'FontFamily' => 'GE Inspira') );
// $content_text->setTextWrap();
//}
//else
//{
//$content_text = &$workbook->addFormat( array( 'border'=>'1','Size' => '12', 'align'=>'center' ,'FontFamily' => 'GE Inspira') );
// $content_text->setTextWrap();
//}
//$worksheet->write($row_num,0,$val['variable1'],$content_text );
//$worksheet->write($row_num,1,$val['variable2'],$content_text );
//$worksheet->write($row_num,2,$val['variable3'],$content_text );
//$worksheet->write($row_num,3,$val['variable4'],$content_text );
//$worksheet->write($row_num,4,$val['variable'],$content_text );
//$worksheet->write($row_num,5,$val['variable'],$content_text );
//$worksheet->write($row_num,6,$val['variable'],$content_text );
//$worksheet->write($row_num,7,$val['variable'],$content_text );
//$worksheet->write($row_num,8,$val['variable'],$content_text );
//$worksheet->write($row_num,9,$val['variable'],$content_text );
//$worksheet->write($row_num,10,$val['variable'],$content_text );
//$worksheet->write($row_num,11,$val['variable'],$content_text );
//$worksheet->write($row_num,12,$val['variable'],$content_text );
//$worksheet->write($row_num,13,$val['variable'],$content_text );
//$worksheet->write($row_num,14,$val['variable'],$content_text );
//$worksheet->write($row_num,15,$val['variable'],$content_text );
//$worksheet->write($row_num,16,$val['variable'],$content_text );
//$worksheet->write($row_num,17,$val['variable'],$content_text );
//$worksheet->write($row_num,18,$val['variable'],$content_text );
//$worksheet->write($row_num,19,$val['variable'],$content_text );
//$worksheet->write($row_num,20,$val['variable'],$content_text );
// $worksheet->write($row_num,21,$val['variable'],$content_text );
//$worksheet->write($row_num,22,$val['variable'],$content_text );
//$worksheet->write($row_num,23,$val['variable'],$content_text );
//if( !isset($val['variable'] ) || empty( $val['variable'] ) || $val['variable'] )
// $acceptance_date='NULL';
//else
// $acceptance_date=$model->date( Yii::app()->params['php_dateformat_datepicker'], strtotime( $val['variable'] ) );
//$worksheet->write($row_num,24,$acceptance_date,$content_text );
//$worksheet->write($row_num,25,$val['variable'],$content_text );
$row_num++;
}
$workbook->send('NTP ' .$id .' SID ' .$sid. ' Extraction Checklist.xls');
$workbook->close();
}
正如你所看到的那样,我现在已经将数据拉出来了(我已经在各个变量被拉入的所有位置都列出了“变量”,并且我仔细检查以确保变量是正确的。我甚至尝试了一个一个留下一个数据拉变量工作,看看我是否能找到它只是其中一个有困难的项目。
我也尝试将文件类型更改为.xslx无效。
与2008年相比,2012年的机器是否有特定的东西可能导致这个问题?或者您是否在代码中发现可能是我的问题的问题。