Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Basic Word integration using docx template files and PHPWord
#1

[eluser]digitalhuman[/eluser]
Another simpel/basic Word library added for CodeIgniter users. We just use template files, fill it with the data it requires and save it to new file. Simple easy but affective. With thanks to the one who build the PHPWord class CodePlex http://phpword.codeplex.com/releases/view/49543

1. Unpak the whole zip file in your /Application/Libraries folder.
2. Add a template file path to your config.php file:

$config['office_templates_path'] = APPPATH . '/../templates';

3. Copy the Template.docx file to ^ that location
4. Use it as any other library, see the example below:

Code:
$this->load->library("phpoffice");
$this->phpoffice->set_template("Template.docx");
$data = array(
array(
  "field" => 'Value1',
  "value" => 'Hi whats up?'
)
);
  
if(($file = $this->phpoffice->create_document($data)) !== false){
if(($res = $this->phpoffice->save_document("mynewdoc.docx", APPPATH . "/../documents/word")) == true){
  services::debug("Ok");
}else{
  services::debug("NoK");
}  
}else{
services::debug("Something went wrong");
}

More info: http://victorangelier.blogspot.com or twitter: @digital_human
#2

[eluser]heru[/eluser]
hi digitalhuman. i got this error message. what does it mean ?
please help.
#3

[eluser]heru[/eluser]
solved. but now it's just showing blank page. why is that ?
#4

[eluser]digitalhuman[/eluser]
I'm sorry, i didn't saw these posts before.

Heru, showing a blank page means something went seriously wrong. Turn on error reporting. Like this:

error_reporting(E_ALL); ini_set('display_errors', 1);

You first post;

Please show me the code you have so i can help you out better. I turned on notification now Smile
#5

[eluser]heru[/eluser]
it's okay victor. i turned error reporting like you said, and the result is same, blank page.
this is my code :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
  error_reporting(E_ALL); ini_set('display_errors', 1);
  $this->load->library("phpoffice");
  $this->phpoffice->set_template("Template.docx");
  $data = array(
  array(
  "Value1" => "Value1",
  "Value2" => 'Hi whats up?',
  "Value3" => 'Hi whats up?',
  "Value4" => 'Hi whats up?',
  "Value5" => 'Hi whats up?',
  "Value6" => 'Hi whats up?',
  "Value7" => 'Hi whats up?',
  "Value8" => 'Hi whats up?',
  "Value9" => 'Hi whats up?',
  "Value10" => 'Hi whats up?'
  )
  );
  if(($file = $this->phpoffice->create_document($data)) !== false){
   if(($res = $this->phpoffice->save_document("mynewdoc.docx", APPPATH . "/../documents/word")) == true){
    services::debug("Ok");
    }else{
     services::debug("Something went wrong");
    }  
  }
}
}
#6

[eluser]digitalhuman[/eluser]
[quote author="heru" date="1371195116"]it's okay victor. i turned error reporting like you said, and the result is same, blank page.
this is my code :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
  error_reporting(E_ALL); ini_set('display_errors', 1);
  $this->load->library("phpoffice");
  $this->phpoffice->set_template("Template.docx");
  $data = array(
  array(
  "Value1" => "Value1",
  "Value2" => 'Hi whats up?',
  "Value3" => 'Hi whats up?',
  "Value4" => 'Hi whats up?',
  "Value5" => 'Hi whats up?',
  "Value6" => 'Hi whats up?',
  "Value7" => 'Hi whats up?',
  "Value8" => 'Hi whats up?',
  "Value9" => 'Hi whats up?',
  "Value10" => 'Hi whats up?'
  )
  );
  if(($file = $this->phpoffice->create_document($data)) !== false){
   if(($res = $this->phpoffice->save_document("mynewdoc.docx", APPPATH . "/../documents/word")) == true){
    services::debug("Ok");
    }else{
     services::debug("Something went wrong");
    }  
  }
}
}
[/quote]

Well i don't think you have my 'services' modal. So, remove all: services::debug()

Can it access the Template.docx file?, Does this path exist: APPPATH . "/../documents/word" on your server?
#7

[eluser]heru[/eluser]
ok, i removed it. anyway, what is "your services modal" ?
yes, you mean like this, right ?
#8

[eluser]digitalhuman[/eluser]
Yes idd. But is that directory writable for the webserver?
#9

[eluser]digitalhuman[/eluser]
[quote author="heru" date="1371195943"]ok, i removed it. anyway, what is "your services modal" ?
yes, you mean like this, right ?
[/quote]

Thats my modal with the name 'services' which has a lot of tools and thinks.
#10

[eluser]heru[/eluser]
[quote author="digitalhuman" date="1371196312"]Yes idd. But is that directory writable for the webserver?[/quote]

yes, it's writeable. and, still blank page. i don't know what's wrong with my code :-S




Theme © iAndrew 2016 - Forum software by © MyBB