-
-
Notifications
You must be signed in to change notification settings - Fork 638
Enable est column width calculation #866
base: master
Are you sure you want to change the base?
Changes from all commits
4f0e72c
d53be7b
8ba78df
a41040d
88afc3d
1b45aff
ea22cac
0a56c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Box\Spout\Writer\Common\Helper; | ||
|
||
class AppendHelper { | ||
|
||
/** | ||
* Instead of seeking and re-writing from position, a better hack might be to write dummy empty data | ||
* Enough to take care of any length, then carefully overwrite | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that's the strategy I've used elsewhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adrilo Benchmark result with overwriting empty spaces... (negligible again but may be useful) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested 5,000 rows, 500,000 rows and 50,000 rows... The script is included below..
|
||
* | ||
*/ | ||
|
||
/** | ||
* This function will truncate from specified position | ||
* Write data to be inserted and re-append the truncated data | ||
* | ||
* @param $fp Pointer to file only | ||
* @param $pos Position to insert | ||
* @param $content Content to insert | ||
*/ | ||
public static function insertToFile($fp, $pos, $content) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be very costly to rewrite the contents, especially with large spreadsheet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I will try both approaches and do a benchmark today. It didn't seem to matter for small files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adrilo So I ran some tests and this is not actually a bad solution at all... (performance differences range from 3% to 7% and seems to get better for larger amount of rows).. (Only tested 100,000, 500,000 and 1 million rows though) The difference are quite negligible most likely because the file is still in memory the whole time and the only costly operation here is really calling |
||
{ | ||
fseek($fp, $pos); | ||
$trailer = stream_get_contents($fp); | ||
ftruncate($fp, $pos); | ||
fseek($fp, $pos); | ||
fwrite($fp, $content); | ||
fwrite($fp, $trailer); | ||
return $fp; | ||
} | ||
|
||
/** | ||
* This function overwrite data in pointer from specified position | ||
* | ||
* @param $fp Pointer to file only | ||
* @param $pos Position to insert | ||
* @param $content Content to insert | ||
*/ | ||
public static function overwriteToFile($fp, $pos, $content) | ||
{ | ||
$cur = ftell($fp); | ||
fseek($fp, $pos); | ||
fwrite($fp, $content); | ||
fseek($fp, $cur); | ||
return $fp; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you come up with the 1.2 ratio?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually meant to be 700/400.. but the 1.2 seemed to fit better.. and that may be because tinier letters like 'i', like you rightly pointed out; occupy less space..