As the title says, I am trying to open a CSV file that is comma delimited and I need to update specific part of the CSV string. Is that possible? I have looked into fseek but that only let's me count the number of bytes from the BOF so that won't work as each CSV would be different.
I was thinking if it was possible if I set the specific part I want to change with something like "CHANGEME" and have PHP look for that string/character and replace that with whatever I need.
Possible?
Try fgetcsv (documentation) or str_getcsv.
Maybe these functions will help.
Related
Recently I mastered fgetcsv in the hope of writing an array to a file so that I could later open it via Excel, there was no problem with it. Everything turned out ok. But, as far as I understand, there can not be done so to automatically push apart the cells to the length of the string (maybe looked bad)
Now it is written like this:
I want to know are there are any libraries, so that the cells length is set to the length of the string written to the cell?
It is necessary that it was like this:
Or maybe there is another approach? For example, manually in Excel to convert all at once so?
I will be grateful for any help, thanks!
CSV files doesn't have any cell length defintion
They are text files, with Comma Seperated Values (CSV ...)
xlsx files however DO hold such a feature
They are basically xml zipped
You can either look for a php excel library with a function ready or parse the XML yourself...
XML sturcture is reffred to here
Looking for a clear description of Excel's .xlsx XML format
Worksheets("Sheet1").Columns("A:D").AutoFit
I have two file pdf, 1st file containing the chart and 2nd file contains information chart.
How to pair the two files back together, right with the position of each page.
I using php,apache2,ubuntu.
Thanks!
Well your question is very ambiguous but going by what I understand, I think you would first need to extract the contents of both pdf's and then map them according to their values from pdf1 to pdf2. For this you can use Tesseract OCR to extract the data and then by writing your code you can try and match them according to their position on page.
Maybe if you just elaborate your question a bit I could help you more.
I have an excel file with a large amount of strings in a column. I want to add these to an array in a php file, so I want each cell in the column to be enclosed in apostrophe's and insert a comma between each. I tried copying the excel column to word and doing a find and replace in word but it uses a different apostrophe type. Any ideas?
Export the Excel file to .csv, then you can either learn to read .csv files from PHP, e.g., from this tutorial, or do something more pragmatic like open the file in a text editor like BBEdit and select the column you want using block-select mode, discarding the rest of the document.
I'm not so sure about the """ but I used a similar method to create SQL queries from cells.
="""&A1&""","""&B1&""", ...
This would be one of my first PHP projects.
Where to start in PHP for a script that rearranges tab delimited data.
I have a tab delimited data text file that needs to be rearranged periodically. Some entire columns would have to move to different parts of the text file, and some headers of columns need to be renamed as well. Basically my tab delimited data file is being converted to match another tab delimited data set to fit a system. (Actually the file is an Amazon.com SELLER CENTRAL Order Reports tab delimited text file that is in a different format from tab delimited text files downloaded from Amazon.com's own MARKETPLACE Order Reports)
I hope someone can give me some direction as to where I would start writing code or how to make this script work...
You can read in the TSV file using PHP's fgetcsv(), using "\t" as the delimiter.
This gives you an array of columns that you can manipulate as you require. Once done, you can then write the array as a line in a new file using fputcsv()
Edit: As an example, the process would go something like
Open file handles (using fopen()) to your existing data file (source) and the new destination file
Read in the source file line-by-line using fgetcsv()
Create a new array of columns using the values returned by fgetcsv() in the order required
Write the new array to the new file using fputcsv()
Once done, close both file handles
Surely you have to know here
To match the TAB inside php you use the string: "\t"
Next you will need the explode function to obtain the array from one row of the file
next you'll need foreach cycling among the array elements to analyse the data
of course the Arrays in PHP will always help you
and at the end when you'll need produce the final TAB delimited file you'll need the implode
Of course take a look at string and array functions in PHP.
Parse the data using fgetcsv() and use array_multisort(). If you need an example, there's one available on the multisort manual page.
I know the names of the columns I want to keep in the .csv file, but I am interested in removing all columns in the .csv which I don't recognize. How can php do this?
(The names of the columns are defined in the first row of the file.)
In PHP use fgetcsv() to read in your CSV file, ignore the columns you want and then write back to a CSV file using fputcsv();
Look at fgetcsv and fputcsv. Read the contents, write the columns/data back out that you want.