Read an excel file. only Column A can be read.
Function import_excel ($ filePath) {$ txt = array (); $ PHPReader = new PHPExcel_Reader_Excel2007 (); if (! $ PHPReader-> canRead ($ filePath) {$ PHPReader = new PHPExcel_Reader_Excel5 (); if (! $ PHPReader-> canRead ($ filePath) {echo 'no Excel '; return ;}// create an excel Object. in this case, you can use an excel Object to read files, you can also use it to write $ PHPExcel = $ PHPReader-> load ($ filePath ); /** read the first worksheet in the excel file */$ currentSheet = $ PHPExcel-> getSheet (0 ); /** obtain the largest column number */$ allColumn = $ currentSheet-> getHighestColumn (); /** obtain the total number of rows */$ allRow = $ currentSheet-> getHighestRow (); echo "allcolumn :". $ allColumn."
"; Echo" allRow: ". $ allRow ."
"; // Read the content of each cell cyclically. Note that the row starts from 1 and the column starts from A for ($ rowIndex = 1; $ rowIndex <= $ allRow; $ rowIndex ++) {for ($ colIndex = 'a '; $ colIndex <= $ allColumn; $ colIndex ++) {echo $ colIndex. ","; $ addr = $ colIndex. $ rowIndex; $ cell = $ currentSheet-> getCell ($ addr)-> getValue (); $ txt [$ rowIndex] [] = $ cell; echo $ cell ,", ";} echo"
";}Return $ txt ;}
Only the content of column A can be read, and none of the following can be read.
Is it for ($ colIndex = 'a'; $ colIndex <= $ allColumn; $ colIndex ++) to transcode?
Reply to discussion (solution)
Echo "allcolumn:". $ allColumn ."
";
What is this output?
For ($ colIndex = 'a'; $ colIndex <= $ allColumn; $ colIndex ++ ){
$ ColIndex = 'a ';
$ ColIndex ++
A is A character ,? Row ++ only ?? The value is 1.
So every time it is 1
Change?
For ($ colIndex = 0; $ colIndex <= $ allColumn; $ colIndex ++ ){
??
Please do not mislead the author's code.
for($i='A'; $i!='AA'; $i++) echo $i;
ABCDEFGHIJKLMNOPQRSTUVWXYZ
For ($ colIndex = 'a'; $ colIndex <= $ allColumn; $ colIndex ++ ){
$ ColIndex = 'a ';
$ ColIndex ++
A is A character ,? Row ++ only ?? The value is 1.
So every time it is 1
Change?
For ($ colIndex = 0; $ colIndex <= $ allColumn; $ colIndex ++ ){
??
Please do not mislead the author's code.
for($i='A'; $i!='AA'; $i++) echo $i;
ABCDEFGHIJKLMNOPQRSTUVWXYZ
For ($ colIndex = 'a'; $ colIndex <= $ allColumn; $ colIndex ++ ){
$ ColIndex = 'a ';
$ ColIndex ++
A is A character ,? Row ++ only ?? The value is 1.
So every time it is 1
Change?
For ($ colIndex = 0; $ colIndex <= $ allColumn; $ colIndex ++ ){
??
Understand, if ???? Not here ?? .
What is the output of the landlord's code?
Echo "allcolumn:". $ allColumn ."
";
The output is AD.
Cannot be changed to a number ??
Moderator:
For ($ I = 'a'; $ I! = 'A'; $ I ++) echo $ I;
$ I! = 'A'. how can I deal with the last AA? I have not read the last column.
Me first
$ AllColumn ++
You can read the last row.
Another problem is that I want to output text
For ($ rowIndex = 1; $ rowIndex <= $ allRow; $ rowIndex ++ ){
For ($ colIndex = 'a'; $ colIndex! = $ AllColumn; $ colIndex ++ ){
$ Addr = $ colIndex. $ rowIndex;
$ Cell = $ currentSheet-> getCell ($ addr)-> getValue ();
$ Txt. = $ cell. "\ t ";
}
$ Txt. = "\ n ";
}
Result:
Transaction Date Order Id Transaction ID Order State SKU Product Link Variation Price (each) Cost (each) Shipping Cost (each) quantity Total Cost Shipped on Provider Tracking Shipping Address Name First Name Last Name Street Address 1 Street Address 2 City State Zipcode Country Last Updated Phone Number Country Code
All outputs are blank.
\ T and \ n are displayed as spaces when you watch the video in the browser, because they are control operators in the text mode.
If you want to display the content in the browser in text format, you need to put the content in pre-formatted tags (pre, xmp ).
$ File = import_excel ("../upload/123.xlsx ");
$ Order_array = explode ("\ n", $ file );
Foreach ($ order_array as $ value ){
$ Aa = explode ('', $ value );
Print_r ($ aa );
}
None of my output results are correct.
Array ([0] => Transaction Date [1] => [2] => Order Id [3] => [4] => Transaction ID [5] => [6] => Order State [7] => [8] => SKU [9] => [10] => Product [11] => [12] => Product Link [13] => [14] => Variation [15] => [16] => Price (each) [17] => [18] => Cost (each) [19] => [20] => Shipping (each) [21] => [22] => Shipping Cost (each) [23] => [24] => Quantity [25] => [26] => Total Cost [27] => [28] => Shipped on [29] => [30] => Provider [31] => [32] => Tracking [33] => [34] => Shipping Address [35] => [36] => Name [37] => [38] => First Name [39] => [40] => Last Name [41] => [42] => Street Address 1 [43] => [44] => Street Address 2 [45] => [46] => City [47] => [48] => State [49] => [50] => Zipcode [51] => [52] => Country [53] => [54] => Last Updated [55] => [56] => Phone Number [57] => [58] => Country Code [59] => [60] =>)
How can I remove spaces and tabs on both sides of a string ???
$ File = import_excel ("../upload/123.xlsx ");
Post-ptint_r ($ file); to see what it is
$ File is the output text.
Transaction Date Order Id Transaction ID Order State SKU Product Link Variation Price (each) Cost (each) Shipping Cost (each) quantity Total Cost Shipped on Provider Tracking Shipping Address Name First Name Last Name Street Address 1 Street Address 2 City State Zipcode Country Last Updated Phone Number Country Code 04-12-2015 without using APPROVED 6402-BK Neewer 3.5mm Jack Retractable auxiliary Cord for iPod/MP3 Players/Cell Phones-6402-BK https://www.wish.com/c/53f179f21c105e50bba1b5b8 N/a $1.99 $1.69 $0.00 $0.00 1 $1.69 Loay Alsalih 7919 S 82 nd. ct Apt. 3 S Justice Illinois 60458 United States 7085487881 Loay Alsalih 7919 S 82 nd. ct Apt. 3 S Justice IL 60458 United States 04-13-2015 7085487881 US 04-12-2015 552abba85633ba0be6cbf1ab paiapproved 6452-00 Extendable Handheld Selfie Stick Monopod Holder For iPhone Samsung Phones https://www.wish.com/c/53fefa589020ee2b46eb8ab0 Color: black 9.99 $8.49 $0.00 $0.00 1 $8.49 Jonas Pettersson Skaraborgsv ägen 3 ROSVIK None 94533 Sweden 070 558 71 60 Jonas Pettersson Skaraborgsv ägen 3 ROSVIK 94533 Sweden 04-13-2015 070 558 60 SE 04-12-2015 552ac7d3bd74230c00e30781 552ac7d2be481_cc1704ef2 APPROVED 6634-00 BLA-7 Fheimin®2014 new spring high-heeled shoes wedding shoes platform fashion women shoes pumps red bottom high heels 14 cm https://www.wish.com/c/53e05f62d911394475ed77fe Size: 7, color: black $24.99 $21.24 $4.00 $3.40 1 $24.64 Jamie 107 e overton st Overton Texas 75684 United States 9038060856 Jamie Jami Jamie 107 e overton st Overton TX 75684 United States 04-13-2015 9038060856 US 04-12-2015 552acffdcaf0e00beb89afea 552acff273f6810cb5d34baa APPROVED 6007-3 M Fheimin®Extra Long 3 m 10ft Long USB Data Charger Sync Cable for iPhone 5 5 5G iPad Mini iPod Touch 5 5G iPod Nano 7 7G-6007-3M https://www.wish.com/c/53eb0924104dae3decadab9a N/a $3.99 $3.39 $0.00 $0.00 1 $3.39 Nuno Cardoso ?molnv ädersgatan 30 Lgh 1201G öteborg None 41835 Sweden 076 279 57 23 Nuno Cardoso Fragueiro Nuno Cardoso ?lnmov ädersgatan 30 Lgh 1201 Göteborg 41835 Sweden 04-13-2015 076 279 57 23 SE 04-12-2015 552ad57ce508974e53e20748 450approved 6062-00 Fheimin®TSdena mobile multi-functional digital scale (scales) 0.01g units/up to 100g pocket scale HEM-KDSP01001S-S (japan import)-6062-00 https://www.wish.com/c/53eb1df81f506345376506d7 N/a $9.99 $8.49 $0.00 $0.00 1 $8.49 Shanne Botizan 931 National road Wheeling West Virginia 26003 United States 3043127670 Shanne Botizan 931 National road Wheeling WV 26003 United States 04-13-2015 3043127670 US 04-12-2015 552ae00067bd420bf1830c8f 552ae0001f1b330cc784fb50 APPROVED 6105-WH Mini Charger micro chargeur allume cigare usb (Shipping to France Only) https://www.wish.com/c/540d30087f086e6cbdc659a9 N/a $1.99 $1.69 $1.00 $0.85 1 $2.54 Csokany ana 41bis rue Auguste renoir Appartement A20 31200 Toulouse 31200 France 0662214649 Csokany ana ready ana 41bis rue Auguste renoir Appartement A20 31200 Toulouse 31200 france 04-13-2015 0662214649 FR 04-12-2015 g0paiapproved 6106-MX kit caricabatterie per iPhone 3G 3GS 4 4S S caricatore da muro auto/macchina + cavo usb (shipping to Italy Only) https://www.wish.com/c/540d58677a9eb43980922bd3 N/a $4.99 $4.24 $4.00 $3.40 1 $7.64 Aggoune sahra 1 rue de mon desert Nancy None 54000 France 0761632175 Aggoune sahra 1 rue de mon desert Nancy 54000 France 04-13-2015 0761632175 FR 04-13-2015 552b08afbd74230c0de30b88 552b08ad1e260e0cac3bf3ee APPROVED 6452-BL Extendable Handheld Selfie Stick Monopod Holder For iPhone Samsung Phones https://www.wish.com/c/53fefa589020ee2b46eb8ab0 Color: blue $9.99 $8.49 $0.00 $0.00 1 $8.49 Gabriel sanchez 2118 NE 10 Pl Ocala Florida 34470 United States 3525029526 Gabriel sanchez 2118 NE 10 Pl Ocala FL 34470 United States 04-13-2015 3525029526 US 04-13-2015 552b10bbbdc6040bd2a84eac 552b10bb73f6810cb2dda-c APPROVED 6634-00 BLA-8.5 Fheimin®2014 new spring high-heeled shoes wedding shoes platform fashion women shoes pumps red bottom high heels 14 cm https://www.wish.com/c/53e05f62d911394475ed77fe Size: 8.5, color: black $24.99 $21.24 $4.00 $3.40 1 $24.64 Destanie Finley 6200 college ave Snyder Texas 79549 United States 3256426040 Destanie Finley 6200 college ave Snyder TX 79549 United States 04-13-2015 3256426040 US
Done.
Add $ cell = str_replace ("\ n", '', $ cell); // clear the line break