How to use two different outputs of one TV in MODX? - modx

I have TV with input type "File". How can i use output of this file few times:
1. in one place as url
2. in one place as name of this file
3. in one place as size of this file
Thank you

1 - use your tv - My File
2 - use snippet like this -
[[!getNameFromPath?&path=`[[*myFileTv]]`]]
and code of this snippen is -
<?php
$path = $modx->getOption('path', $scriptProperties, '');
$fileName = basename($path);
return $fileName;
3 - use another snippet -
[[!getSizeFromPath?&path=`[[*myFileTv]]`]]
which code is -
<?php
$path = $modx->getOption('path', $scriptProperties, '');
if (!empty($path)) {
$size = filesize(MODX_BASE_PATH . ltrim($path,'/'));
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
if ($size == 0) {
return('n/a');
} else {
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]);
}
}

You will have to create a snippet to output the parameter you want.. something like:
[[!outputMyFile? &attribute=name &tv=[[*myTvValue]]]]
where the snippet will do your processing on the TV value [the file name] and output the appropriate attribute you want.

Related

Sometimes having Excel export problems

I have a problem, I'm importing cycling a Table to Excel.
My code is look like this :
#WINAPI
#Excel
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelCells cells;
SysExcelCell cell;
SysExcelRange columns;
while select myTable
{
cell = sheet.cells().item(row, col);
cell.value(myTable.FieldI);
sheet.columns().autoFit();
col++;
cell = sheet.cells().item(row, col);
cell.value(myTable.FieldII);
sheet.columns().autoFit();
col++;
row++;
col=1;
}
// when the cycle end save my file
But sometimes I give an error look like message debug
"Wrong argument types in variable assignment"
or
"The number of arguments provided is different from the number of arguments accepted by the method"
But the weird thing is if i try againg to re-launch the export I will not get the errors.
I have this problem
I have same code and same data.
When I generate the file the excle rows are perfect.
I have this problem in 50% of these cases.
The rows created are 1700 more less.
What does it depend on? I have a lot rows? Or other?
I share the same question found on web Some question ,I tried to use, but did't solved my problem:
I add more information not slved my problem change settings
Thanks in advice,
enjoy
Yes, when develop any export Excel had this problem, when many rows. If there are few rows it works perfect.
For this cases always change the excel export for CSV export. The code to export csv file never fail and work perfect!
Here I leave an example to export csv file with 5 rows.
Code:
static void ExportCSV(Args _args)
{
Commaio file;
container lineCSV;
#File
str DatosLinea[500];
int _i;
str filename;
Dialog dialog;
DialogField dialogFileName;
;
dialog = new Dialog("Path CSV");
dialogFileName = dialog.addField(ExtendedTypeStr("FilenameSave"),"Path File:");
if (dialog.run())
{
filename = dialogFileName.value();
}
if (!filename)
{
return;
}
file = new Commaio((filename), 'W'); //Path + file name.csv
file.outFieldDelimiter(';');
if( !file || file.status() != IO_Status::Ok)
{
throw error("File Cannot be opened");
}
DatosLinea[1] = "Col 1";
DatosLinea[2] = "Col 2";
DatosLinea[3] = "Col 3";
DatosLinea[4] = "Col 4";
DatosLinea[5] = "Col 5";
_i = 1;
lineCSV = conNull();
while(_i <= 5){
lineCSV += DatosLinea[_i];
_i += 1;
}
file.write(lineCSV);
info("Export end");
}

string get single / multiple values

I have a string
<P>Microsoft Word 2003 Service Pack 3 <BR>(2863866)</P>`
from which I need to get out 3 values:
- $value1 = characters between " "
- $value2 = characters between "> </A
- $value3 = characters between ( )
Any idea how to achieve this?
Try regex:
$string = '<P>Microsoft Word 2003 Service Pack 3 <BR>(2863866)</P>`'
$regex = '"(.*?)">(.*?)<\/A>.*?\((.*?)\)'
if($string -match $regex) {
$Matches[1]
$Matches[2]
$Matches[3]
}
http://www.microsoft.com/downloads/details.aspx?FamilyId=39d8f0cd-4043-4eed-bd27-2f26748da664
Microsoft Word 2003 Service Pack 3
2863866
This would require all elements to always be there and in the same order (link, name of link, parantheses)

search for a cell from one excel and search in another excel and print if its not there using perl

I'm new to perl. I have two excel files containing huge no of rows and just two columns. I want to get each cell from one of the excel files and search whether its there in another excel file or not. if its not then print that cell.
I believe that if I get each cell from one of the excel and search it in another and then run a for loop for all the rows it will be done.
I reached upto getting the cell from first excel but how to search whether it is there in the another excel and printing it is the issue.
can anybody help. ??
I'm not entirely sure what you want, but this might give you some ideas. It's completely untested, though.
use strict;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook1 = $parser->parse('Book1.xls');
if (!defined $workbook1) { die $parser->error(), ".\n"; }
my $workbook2 = $parser->parse('Book2.xls');
if (!defined $workbook2) { die $parser->error(), ".\n"; }
$worksheet1 = $workbook1->worksheet('Sheet1');
$worksheet2 = $workbook2->worksheet('Sheet1');
my ($row_min1, $row_max1) = $worksheet1->row_range();
my ($col_min1, $col_max1) = $worksheet1->col_range();
for my $row1 ($row_min1 .. $row_max1) {
for my $col1 ($col_min1 .. $col_max1) {
my $cell1 = $worksheet1->get_cell($row1, $col1);
my ($row_min2, $row_max2) = $worksheet2->row_range();
my ($col_min2, $col_max2) = $worksheet2->col_range();
my $found_match = 0;
for my $row2 ($row_min2 .. $row_max2) {
for my $col2 ($col_min2 .. $col_max2) {
my $cell2 = $worksheet2->get_cell($row2, $col2);
if ($cell1->value() eq $cell2->value()) { # or == ?
$found_match = 1;
break;
}
}
break if $found_match;
}
if (!$found_match) {
print $cell1->value, "\n";
}
}
}
This is mostly from here: http://search.cpan.org/dist/Spreadsheet-ParseExcel/lib/Spreadsheet/ParseExcel.pm

search view with the exact value

I have a view in which I search for products. I'm for example looking for product 1234.
The problem is their also exist products called 1234A and 1234 C etc. When I look with the code mentioned below I get all the items from product 1234 but also from 1234A and 1234 C etc.
It has to be limited to items from product 1234 only
Search code (under Data / Search in view results):
var tmpArray = new Array("");
var cTerms = 0;
if (sessionScope.SelectedProduct != null & sessionScope.SelectedProduct != "") {
tmpArray[cTerms++] = "(FIELD spareProduct = \"" + sessionScope.SelectedProduct +
"\")";
}
if (sessionScope.Development != null & sessionScope.Development != "") {
tmpArray[cTerms++] = "(FIELD spareStatus = \"*" + sessionScope.Development +
"*\")";
}
qstring = tmpArray.join(" AND ").trim();
return qstring
I used the suggestion from Frantisek :
I made a view with a combined column . (combined with the different "keys" I search for)
Then instead of using data / search , I used data/keys with exact keymatch. In this key I combined the searched items.
Since I had a field in wich I had sometimes at the end a character "°" , and it seems that this character doesn't work with a lookup , I took it out of my view and searched item with #Word(FIELDNAME; "°" ; 1).
As Frantisek suggested I could have used #ReplaceSubstring( field; "°"; "" ) also.

Sharepoint 2010 How to use "File Size" column value in a formula?

I am trying to use "File Size" (aka "FileSizeDisplay") in a Calculated column formula.
"File Size" is an existing column (default SP not custom).
But is not available in the "Insert Column" list of any library.
And SP displays an error message that states it does not exist if it is added to a formula manually as either [File Size] or [FileSizeDisplay].
All I want to do is inform a user that an image is too big. Not trying to prohibit file size upload or anything technical like that. Just want a Calculated column to display a message.
If the column value was available the following would work:
=IF([File Size]>50000,"Image is too big","Image is sized correctly")
or
=IF([FileSizeDisplay]>50000,"Image is too big","Image is sized correctly")
Any one know why this column is not available?
Cheers
You'll want to get the file size first: get file size then you can display of message in a pop up or how ever you'd like
using System;
using System.IO;
class Program
{
static void Main()
{
// The name of the file
const string fileName = "test.txt";
// Create new FileInfo object and get the Length.
FileInfo f = new FileInfo(fileName);
long s1 = f.Length;
// Change something with the file. Just for demo.
File.AppendAllText(fileName, " More characters.");
// Create another FileInfo object and get the Length.
FileInfo f2 = new FileInfo(fileName);
long s2 = f2.Length;
// Print out the length of the file before and after.
Console.WriteLine("Before and after: " + s1.ToString() +
" " + s2.ToString());
// Get the difference between the two sizes.
long change = s2 - s1;
Console.WriteLine("Size increase: " + change.ToString());
}
}

Resources