21,886
社区成员
发帖
与我相关
我的任务
分享
//导出
public function export(){
if($this->request->isPost()){
try {
$msproject = new \DOTNET("Microsoft.Office.Interop.MSProject,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c","Microsoft.Office.Interop.MSProject.ApplicationClass");
//$msproject= new \COM('MSProject.application');
} catch (Exception $e) {
$message = array('result'=>'fail','message'=>"组件连接失败");
return $message;
}
$adr = ROOT_PATH."public/static/office/mpt/branch.mpt";
try {
$msproject->FileNew(null,$adr,null,null);
} catch (Exception $e) {
$message = array('result'=>'fail','message'=>"打开文件失败");
return json($message);
}
$msproject->ActiveProject->StartOnCurrentDate = true;
$data=model('ItemPlan')->get_one_data(input('id'));
$steps=$data['con'];
if(empty($steps)) {$steps = '{"tasks":[]}';}
$tasks = json_decode($steps)->tasks;
foreach ($tasks as $k => $task) {
$localtask = $msproject->ActiveProject->Tasks->Add(utf82gbk($task->name));
$localtask->Manual = true;
$localtask->OutlineLevel = $task->level;
$localtask->Start = date_format(date_create($task->start_time),"Y/m/d");
$localtask->RemainingDuration = ($task->period);
$localtask->Finish = date_format(date_create($task->end_time),"Y/m/d");
}
//exit();
$rtadr = ROOT_PATH."public/upload/";
$filename = $data['title'].'-'.time().'.mpp';
try {
$msproject->FileSaveAs($rtadr.utf82gbk($filename),0,null,false,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
} catch (Exception $e) {
$message = array('result'=>'fail','message'=>"导出数据失败");
return json($message);
}
$msproject->FileClose(0);
$message = array('result'=>'complete','message'=>$filename);
return $message;
}
}