Re[2]: [PHP-GTK] Editable tables and general planning help
| From: | Tom Rogers | Date: | Fri, 08 Jul 2005 14:11:29 +0000 |
| Subject: | Re[2]: [PHP-GTK] Editable tables and general planning help | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5937@lists.php.net to get a copy of this message | ||
Hi,
Friday, July 8, 2005, 9:59:08 PM, you wrote:
JG> These responses I've been getting are fantastic! Thank you all!
JG> One area which I haven't seen a response to yet is with *copying and
JG> pasting*. Say I'm using a gtksheet (which now seems like the most
JG> sensible solution), and I want to copy and paste data from and to an
JG> Excel spreadsheet into *multiple cells*, how should this be done?
JG> Using GtkSheet I can select a row or a column or a group of cells in a
JG> row or column, but I don't seem to be able to either copy from there or
JG> paste into there using CTR-V or CTR-C.
JG> Has anyone achieved this? I tried searching the mailing list archive but
JG> can't find any answers to this one.
JG> e.g. I may have an Excel spreadsheet with 50 cells in one column which i
JG> want to paste into a GtkSheet. The desired way of doing this would be to
JG> copy from excel and then select one cell in GtkSheet and CTR-V and it'll
JG> paste into that cell and the 49 cells directly below it, in the same way
JG> that it would in Excel or other spreadsheets.
JG> Jake.
I have been playing with pasting from word documents in html format so
I can give you what I have done modified for the excel->sheet bit.
You will need my version of win32api.dll which you can download from:
http://kwiktemplates.com/php_w32api.dll
This code will grab the excel data as csv text and turn it into an
array, after that it should be easy to add it to your sheet. The other
direction will take a bit more research :)
<?php
dl("php_w32api.dll");
$api =& new win32;
$api->registerfunction("bool OpenClipboard
(
long hWndNewOwner
)
From user32.dll");
$api->registerfunction("bool CloseClipboard
(
)
From user32.dll");
$api->registerfunction("int EnumClipboardFormats
(
int format
)
From user32.dll");
$api->registerfunction("int GetClipboardFormatName
(
int format,
string &FormatName,
int cchMaxCount
)
From user32.dll");
$api->registerfunction("long GetClipboardData
(
int uFormat
)
From user32.dll");
$api->registerfunction("string GlobalLock
(
long hMem
)
From kernel32.dll");
$api->registerfunction("bool GlobalUnlock
(
long hMem
)
From kernel32.dll");
$NameSize = 128; //maxsize for returned name
// get a clipboard id
$id = $api->OpenClipboard('');
if($id){
$fn = $api->EnumClipboardFormats(0);
do {
$name = str_repeat("\0", $NameSize); //zero the name holder
$api->GetClipboardFormatName($fn,$name,$NameSize);
if(preg_match('/CSV/i',$name)){
$data_handle = $api->GetClipboardData($fn);
if($data_handle){
$text = trim($api->GlobalLock($data_handle));
echo $text;
$rows = explode("\r\n",$text);
foreach($rows as $key=>$row){
$rows[$key] = explode(',',$row); //add columns
}
print_r($rows);
$api->GlobalUnlock($data_handle);
}
break;
}
//echo "Fn $fn $name\n";
}while($fn = $api->EnumClipboardFormats($fn));
$api->CloseClipboard();
}
?>
To test copy some cells to the clipboard then run this script.
Maybe someone knows how to manipulate the gtk clipboard to achieve the
above ?
--
regards,
Tom