Jump to content
Fórum Script Brasil
  • 0

Ler arquivo xls


Juliet Araujo
 Share

Question

Boa tarde,

Primeiro vou explicar o que preciso...

Tenho a seguinte planilha no excel:

Nome Codigos Ronaldo 4817a7e30f2ffed68042319aaf384593
fe5080bd8719bd2c3b728090dbbf9c65
72db5cd58a880804e9f581ff4a378df1
a3a0ee13dd86c05f6d3981a06be7f785 Juliet 4817a7e30f2ffed68042319aaf384593
fe5080bd8719bd2c3b728090dbbf9c65
72db5cd58a880804e9f581ff4a378df1
a3a0ee13dd86c05f6d3981a06be7f785

Preciso que o PHP leia o xls e gere 2 arquivos txt diferentes exemplo:

ronaldo.txt

4817a7e30f2ffed68042319aaf384593
fe5080bd8719bd2c3b728090dbbf9c65
72db5cd58a880804e9f581ff4a378df1
a3a0ee13dd86c05f6d3981a06be7f785

Juliet.txt

4817a7e30f2ffed68042319aaf384593
fe5080bd8719bd2c3b728090dbbf9c65
72db5cd58a880804e9f581ff4a378df1
a3a0ee13dd86c05f6d3981a06be7f785

Meu problema:

Devido 1 celular ter quatro linhas quando ele gera o txt ele escreve tudo em uma linha e não entende que tem que quebrar a linha.

Será que alguém consegue me ajudar?

<?php

#file_put_contents()
#file_get_contents()
		
require '/Excel/reader.php';

$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');

$data->read('teste2.xls'); // LE O ARQUIVO

	for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
		$numero = $numero+1; // SOMA MAIS 1
		$celldata = utf8_encode((!empty($data->sheets[0]['cells'][$i][2])) ? $data->sheets[0]['cells'][$i][2] : "&nbsp;");

		$cn = 'sambatech'.$numero.'.txt'; //GERA O NOME DO ARQUIVO
		$cd = $celldata; //PEGA O CODIGO
	
		file_put_contents($cn,$cd); // SALVA INFORMAÇÃO DENTRO DO TXT
	}			
?>
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...