function xlsxToCsv($filesXlsx)
{
$customTempFolderPath = (__DIR__ . 'tmp');
// Read the Excel file.
$reader = ReaderEntityFactory::createReaderFromFile($filesXlsx);
$reader->setTempFolder($customTempFolderPath);
$reader->setShouldFormatDates(true);
$reader->open($filesXlsx);
$info = pathinfo($filesXlsx);
// Export to CSV file.
$writer = WriterEntityFactory::createCSVWriter();
//$writer->setTempFolder($customTempFolderPath);
$writer->setShouldAddBOM(false);
$writer->openToFile(safe_file(__DIR__ . "/files/" . $info['filename'] . '.csv'));
// Set delimiter.
$writer->setFieldDelimiter(";");
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
// ... and copy each row into the new spreadsheet
$writer->addRow($row);
}
}
$reader->close();
$writer->close();
}
$dir = realpath('../project.my');
$fileSPLObjects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
foreach($fileSPLObjects as $fullFileName => $fileSPLObject ) {
if ($fileSPLObject->isFile()) {
$info = new SplFileInfo($fullFileName);
if ($info->getExtension() === 'zip') {
zipArchive(basename($fullFileName));
}
}
}
function zipArchive($filesZip)
{
//file_get_contents("zip://files/prices.zip#Price.xls");
/* $zip = new ZipArchive;
if ($zip->open('files/prices.zip') === TRUE) {
echo $zip->getFromName('testfromfile.php');
$zip->close();
} else {
echo 'ошибка';
}*/
// создаём объект
$zip = new ZipArchive();
// открываем архив
if ($zip->open('attach/' . $filesZip) !== TRUE) {
die ("Не могу открыть архив");
}
// переименовываем файл в архиве по его индексу
//$zip->renameIndex(0, 'renamedByIndex.txt') or die("ERROR: не могу переменовать файл");
// переименовываем файл в архиве по его имени
//$zip->renameName("test3.txt", "renamedByName.txt") or die("ERROR: не могу переменовать файл");
// извлекаем содержимое в папку назначения
$zip->extractTo('attach/');
// закрываем и сохраняем архив
$zip->close();
//echo "Файл успешно переименован в архиве archive2.zip!";
}
import imaplib
import email
import os
user = 'ex@gmail.com'
password = '*******'
imap_url = 'imap.gmail.com'
attachment_dir = 'C:/Users/admin/Documents/Attachment'
def auth(user,password,imap_url):
con = imaplib.IMAP4_SSL(imap_url)
con.loggin(user,password)
return con
def get_body(msg):
if msg.is_multipart():
return get_body(msg.get_payload(0))
else:
return msg.get_payload(None,True)
def get_attachments(msg):
for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
fileName = part.get_filename()
if bool(fileName):
filePath = os.path.join(attachment_dir, fileName)
with open(filePath, 'wb') as f:
f.write(part.get_payload(decode=True))
def search(key,value,con):
result, data = con.search(None,key,'"{}'.format(value))
return data
def get_emails(result_bytes):
msgs = []
for num in result_bytes[0].split():
typ, data = con.fetch(num, '(RFC822)')
msgs.append(data)
return msgs
con = auth(user,password,imap_url)
con.select('INBOX')
result, data = con.fetch(b'10','(RFC822)')
raw = email.message_from_bytes(data[0][1])
get_attachments(raw)