PDA

View Full Version : Don't know if this is even possible?


allanforbes
05-22-2016, 05:58 PM
Hi,
I wondered if you might be able to help me find a solution to a coding problem that I have.

I am try to find a way to automate turning information from excel into html pages -

I have an excel spread sheet with my information in column A (over 1000 rows) - and in column B is my list which is the names of the html page that I want to create (containing the infomation from Column A )

I want to avoid having to cut and paste the information from Column A (1000 times) to a new dreamweaver page and then save it as the file name from column B

Any assistance would be greatly welcomed - Thanks

edbr
05-22-2016, 11:14 PM
using php and this phpexcell. https://github.com/PHPOffice/PHPExcel

edbr
05-23-2016, 02:04 AM
This is probably not what you want perhaps if using csv files instead of xls you could try ( php again)
$csvFile = file('../somefile.csv');
$data = [];
foreach ($csvFile as $line) {
$data[] = str_getcsv($line);
}

edited to the file name of course

allanforbes
05-23-2016, 07:38 AM
Hi edbr,
thanks for your replies - can you point me towards any basic websites that I could try to get an understanding of how to achieve this. I use dreamweaver - but am self taught - I have heard of php and csv but have absolutely no idea even where to start or what programs I would need to run them. Do you think I could get someone to write an app to achieve this - cutting and pasting into dreamweaver over a thousand times is so boring??? Many thanks again.

edbr
05-23-2016, 08:03 AM
well the github link might help you.
as for csv you can save an excel file as a csv, (or coma separated file) from the excel program itself.

edbr
05-23-2016, 08:27 AM
http://www.homeandlearn.co.uk/php/php10p6.html might help

edbr
05-23-2016, 08:51 AM
ok i did a test for this
first i made a spreadsheat and saved as test.csv
then i made a php file , i called it test.php ( it can be any name )

and put this in
<?php
echo "<html><body><table>\n\n";
$f = fopen("test.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n</table></body></html>";

?>

upload both files to the same directory. open test.php in a browser and it outputs each line in a table

allanforbes
05-25-2016, 03:54 PM
Sorry edbr - its my fault for not explaining properly - my information in cell A1 has all the information for one complete html page - it has all the html including head / body / internal and external links / jpgs etc etc - I am trying to make 1000+ individual and unique html pages and name them with the file name in cell A2 - I will then be able to add it to my existing pages in a dreamweaver folder.
( At present I have to open excel then copy cell A1 information and then paste it into a blank page in dreamweaver and then save as it with the file name in cell A2 ) then repeat 1000 times

edbr
05-26-2016, 01:49 AM
o my, that's a horse of a different colour. :)
not sure thats possible but there is a function in phpadmin to import a csv file into a data base but never tried it so who knows . maybe.
here are some thoughts though which may or may not be relevant to what you are trying to do. I dont know what the pages are so i can only comment generally
first 100 page site is huge and you need to be sure its really needed. i dont think google is very happy with that for example ( AFIK)

as you are in the state of creating this site it might serve you better that the page content in your spread sheet is separated from the layout html and fetched dynamically form a data base along with the page title and meta description ( for googles sake)
the advantages would make for less fixed pages and by bringing them into a page of your main design much easier to maintain down the line.

another advantage of using a database would be navigation to those pages which would be horrendous with 1000 pages.
It would be possible for example to search by category or date or author (etc) if you added any such paramater into the data base record for each "page"
in any case you are committed to quite a lot of work hers so i would think this is the time to carefully consider your approach now.

edbr
05-26-2016, 02:01 AM
just a file to show hoe php and a database could simplify page construction and maintenance late on , and there will be some im sure

<!doctype html>
<html>
<head>
<meta charset="utf-8">

<!--content fetched from database-->
<title><?php echo $row['title']; ?> </title>
<meta name="description" content="<?php echo $row['description']; ?>">


<link href="layout/layout.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<div id="header"><?php include ('incl/header.php'); ?></div>
<div id="menu"><?php include ('incl/menu.php'); ?></div>

<!--content fetched from database-->
<div id="content"><?php echo $row['content']; ?></div>

<div id="footer"><?php include ('incl/footer.php'); ?></div>
</body>
</html>