data entry into web page from excel - php

I have an excel file with 3 columns, "First name", "Last name", "email" and about 700 entries (rows). I also have a website with a form for first name, last name and email. Obviously I don't want to type out all 700 entries manually. Is there a way to get these columns from excel and enter them into the online form? Perhaps using visual basic/php or any other alternative. If such code already exists then it would be great if somebody could show me. If not, then it would be appreciated if somebody could give some advice on how to approach this. Thanks!

PHP has a CSV method, you can convert/save your excel file to csv and process if using PHP.
Reading the File in PHP
Example 1
How to create an array from a CSV file using PHP and the fgetcsv function
$file = fopen('youruploadedfile.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
// each line of the array
print_r($line);
}
fclose($file);
Example 2
https://www.w3schools.com/php/func_filesystem_fgetcsv.asp
$file = fopen("youruploadedfile.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
check out https://www.w3schools.com/php/func_filesystem_fgetcsv.asp
Definition and Usage
The fgetcsv() function parses a line from an open file, checking for CSV fields.
The fgetcsv() function stops returning on a new line, at the specified length, or at EOF, whichever comes first.
This function returns the CSV fields in an array on success, or FALSE on failure and EOF.
Selenium
Selenium is a tool to automate user interface testing. It helps with testing your application against the browser
Take a look at the web driver https://github.com/facebook/php-webdriver
There is also varied information on how to's on SO.
How to use Selenium with PHP?

Its easier to do this in python/java. Excel is just used to store the list of input values but to actually input it into a webpage using an automated technique you will need to read about webscraping.
Things like BeautifulSoup (a package in python) and Selenium (a java package) can be used for this purpose. You will have to read about them and maybe ask questions to people who know python/java not excel/vba experts.
Here is one link that can get you started
How can I input data into a webpage to scrape the resulting output using Python?
Edit:
I found one link which could help in doing it through VBA but you need to tell us which website only then can someone help you further
Input text into html input box using vba

Related

Edit Excel XML Worksheet File from XLSM in PHP

I have an XLSM File, where I need to edit some Cell Values with PHP. As I couldn't find a proper library, which can actually edit an xlsm file (most read excel and create a whole new excel file, which in this case would delete the macros inside the excel or even throw too many exceptions), I decided to unzip the xlsm file and directly edit the worksheet xml file by changing the values in the cells:
<c r="K15" s="52">
<v>83221.56</v>
</c>
For example I would change the Value inside the "v" Tag.
As Simple XML doesnt work, because it messes up some namespaces inside the file, I decided to edit it with Regular Expressions.
So far so good - i got the change in the file. But Formulars inside the Excel file, that depend on the cell I just changed the Value in won't recognize my change. When you open the Excel file, it properly shows the correct value, but other cells that use that changed value in their formula won't update.
Does anyone have any idea how to properly change the XML File and keeping the excel in tact?
Thanks!
As I could not figure out a solution in PHP and previous solutions with C++ (Is there a PHP library for XLSM(Excel with Macro) parsing/editing?) where to complicated for me, I found a solution with python, I want to share.
My environment is Ubuntu 16.04, I have Python installed. I have installed https://editpyxl.readthedocs.io/en/latest/
I placed a little script in the same directory as the PHP script, which I call with PHP:
from editpyxl import Workbook
import sys
import logging
logging.basicConfig()
if len(sys.argv) != 4:
print("Three arguments accepted, got " + (str(len(sys.argv) -1)))
print("Argument 1: Sheet name, Argument 2: Cell Identifier, Argument 3: New Value")
sys.exit();
wb = Workbook()
source_filename = r'OriginalFile.xlsm'
wb.open(source_filename)
ws = wb[sys.argv[1]]
ws.cell(sys.argv[2]).value = sys.argv[3]
destination_filename = "NewFile.xlsm"
wb.save(destination_filename)
wb.close()
In PHP I call it via
exec('python excel.py "SheetName" "CellName" "NewValue"')
Seems to be a workaround but it works (especially on Linux) and is very easy to implement. This solution has a performance limitation though. The python script reads, changes the value and saves the excel in each runtime. If you only have some values to change, this might not be a problem but if you plan to edit larger Excel Files with a larger amount of cells to edit, you might write the complete code that edits the xlsm in python.
This code, however, works for me. It edits the Excel and all Formulars/Calculations inside stay fine, also the Macros are still untouched.

Get contents from gzipped file

I am trying to get the contents from a gzipped file that is returned to me after using Mailchimp API doing a batch operation request. I expect to get only a JSON string as response, but also receive a bunch of numbers and random (?) strings.
This is what I do.
$gz = gzopen($response->response_body_url, "r");
$contents = trim(gzread($gz, 10000));
print_r($contents); //see output below
gzclose($gz);
This is what is returned to me.
0000777000000000000000000000000012705141572007721 5ustar
rootroot./05fa27ceab.json0000666000000000000000000000121212705141572012327
0ustar
rootroot[{"status_code":400,"operation_id":null,"response":"{\"type\":\"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",\"title\":\"Member
Exists\",\"status\":400,\"detail\":\"xxxx.xxxx#xxxx.xx is
already a list member. Use PUT to insert or update list
members.\",\"instance\":\"\"}"},{"status_code":400,"operation_id":null,"response":"{\"type\":\"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",\"title\":\"Member
Exists\",\"status\":400,\"detail\":\"xxxx2.xxxx2#xxxx2.xx is
already a list member. Use PUT to insert or update list
members.\",\"instance\":\"\"}"}]
What am I missing here? Why won't it work?
It looks like you may be dealing with a .tar.gz file instead of just gzip. The easiest way to do that is either with the PharData extension or by just saving it to disk and using a shell tool to unzip.
Here's an answer to a question on how to deal with .tar.gz files in php

Actionscript - AS 2.0 - PHP copy file from server to server THEN run function

Basic Idea: I have a flash file that takes screenshots with a click of a button, sending the data to a PHP file, and then the user gets to save a PNG image. The images that are merged together (via PHP) require that they reside on the same server as the PHP, otherwise they do not merge and the final PNG shows up blank.
My solution so far: I have two PHP files, and I just need to find a way to merge them. The screenshot one, and one that copies a file from one server to another. This is my cheat work around to bring the image to reside on the same server, THEN run the screenshot php.
The Server-to-Server PHP Code:
<?PHP
$inputfile = FOPEN("https://www.google.com/intl/en_com/images/srpr/logo3w.png", "r");
$outputfile = FOPEN("transferedfile.gif", "w");
ECHO "File opened...";
$data = '';
WHILE (!FEOF($inputfile)) {
$data .= FREAD($inputfile, 8192);
}
ECHO "Data read...";
FWRITE($outputfile, $data);
ECHO "transfered data";
FCLOSE ($inputfile);
FCLOSE ($outputfile);
ECHO "Done.";
?>
So as you can see, it pulls Google's logo and saves it as "transferedfile.gif" to the directory the PHP resides on. I can get this PHP code to work by saving this as whateverIWant.php on my webserver, and visiting it directly, but I need to in place of Google's logo (in this example) put a value that will be dynamically changing via flash.
So basically… in the flash file, I'll have a dyniamic variable where the URL will change, in short. So we'll just say that I define that variable in flash as var imageToGet so somehow I need to pass that variable into this PHP. That's one step... here's the AS 2.0 code:
My Actionscript (2.0) Code:
button.onRelease = function ():Void {
sendImageToServer();
ScreenShot.save(_root, "screenshot.png", 0, 0, 100, 140);
};
the sendImageToServer() function isn't made yet. This is where I'm stuck. I would need the sendImageToServer() function to send var imageToGet as what image to get, THEN run the ScreenShot.save() function after the transfer is done (aka FCLOSE ($outputfile); is complete)
In Summary: A movie clip on the stage will have a dynamic image loaded into it, that once a button is pressed, it would need to copy that dynamic image to the local server, and then run the screenShot function. I believe once I have this figured out, I should be able to do everything else, such as saving as a unique name, saving multiple files, etc. But I just need pushed in the right direction :)
Thanks so much everyone # StackOverflow. You've been nothing but awesome to me thus far!
EDIT -- I've found a good starting point!!
I found a good starting point, and am answering my own question in case someone else stumbles upon this. I used these two codes as a starting point, and I think I'm on the right track…
In Flash: I simply made a dynamic textbox with the instance name of traceText
In Actionscript (2.0):
var send:LoadVars = new LoadVars;
var receive:LoadVars = new LoadVars;
send.toPHP = "asd123";
receive.onLoad = function(){
encrypted = this.toFlash;
traceText.text = encrypted;
}
send.sendAndLoad("test.php",receive,"POST");
In "test.php" file:
$fromFlash = $_POST['toPHP'];
$encrypted = $fromFlash;
$toFlash = "&toFlash=";
$toFlash .= $encrypted;
echo $toFlash;
What this ended up doing was sending the variable to PHP and then back again. Which is perfect for what I needed. For now, I should be good! Hope this helps anyone that needs it.

Use PHP to display a CSV-based Graph

Sorry, I'm a n00b to web languages. I'm trying to upload a CSV file, parse the second and seventh columns, and output it to the Google Graphs API. This is my first ever time trying to do anything with PHP, so, a example would be nice for me to analyze, but, I can try to figure out everything with documentation as well.
Thank you so much for help in any way.
here's how you can upload a file with PHP: http://de3.php.net/move_uploaded_file
Parsing a CSV file is easy:
$csv = file('path/to/file.csv');
foreach ($csv as &$current) {
$current = explode(';', $current);
}
If you then loop through $csv you have the second and seventh column in $csv[$iterator][1] and $csv[$iterator][6].
I haven't used Googles Graph API, so I can't help you with that.
If you're not married to google graphs, try highcharts. I've used it on several occasions and really like it. They have some tutorials and good sample code to look at, too.
Check the other response for parsing a CSV file; it's spot on.
There is a component designed to easily implement the graph by uploading the CSV file: Graph from CSV file

Is it possible to read a pdf file as a txt?

I need to find a certain key in a pdf file. As far as I know the only way to do that is to interpret a pdf as txt file. I want to do this in PHP without installing a addon/framework/etc.
Thanks
You can certainly open a PDF file as text. PDF file format is actually a collection of objects. There is a header in the first line that tells you the version. You would then go to the bottom to find the offset to the start of the xref table that tells where all the objects are located. The contents of individual objects in the file, like graphics, are often binary and compressed. The 1.7 specification can be found here.
I found this function, hope it helps.
http://community.livejournal.com/php/295413.html
You can't just open the file as it is a binary dump of objects used to create the PDF display, including encoding, fonts, text, images. I wrote an blog post explaining how text is stored at http://pdf.jpedal.org/java-pdf-blog/bid/27187/Understanding-the-PDF-file-format-text-streams
Thank you all for your help. I owe you this piece of code:
// Proceed if file exists
if(file_exists($sourcePath)){
$pdfFile = fopen($sourcePath,"rb");
$data = fread($pdfFile, filesize($sourcePath));
fclose($pdfFile);
// Check if file is encrypted or not
if(stripos($data,$searchFor)){ // $searchFor = "/Encrypt"
$counterEncrypted++;
}else{
$counterNotEncrpyted++;
}
}else{
$counterNotExisting++;
}

Categories