getUnderline of excel cellcontent using phpspreadsheet - phpexcel

I have use the code below to find if cell content has been underlined or not using phpexcel
$inputFileType =PHPExcel_IOFactory::identify($file);
$objReader =PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel =$objReader->load($file);
$checkUnderline =$objPHPExcel->getActiveSheet()->getStyle($col.$row)->getFont()->getUnderline();
The answer will be either 'single' or 'none'.
Now, I would like to know how to do this using PHPSpreadsheet.Thank you.

This code works. This link has helped me.
(Read Xlsx file in PhpSpreadsheet)
$inputFileType =\PhpOffice\PhpSpreadsheet\IOFactory::identify($file);
$objReader =\PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$objPHPSpreadsheet =$objReader->load($file);
$cellcontent_underlinestatus =$objPHPSpreadsheet->getActiveSheet()->getStyle($col.$row)->getFont()->getUnderline();

Related

How to select range before convert xlsx to pdf using convertapi

Using convertapi, I would like to set range and convert only selected area to pdf. Is this possible?
<?php
require_once('vendor/autoload.php');
require_once 'vendor/convertapi/convertapi-
php/lib/ConvertApi/ConvertApi.php';
use \ConvertApi\ConvertApi;
ConvertApi::setApiSecret('secret');
$result = ConvertApi::convert('pdf', [
'File' => 'output/spreadsheet_2.xlsx',
], 'xlsx'
);
$result->saveFiles('output');
?>
Thanks in advance.
Currently you can set only WorksheetName or WorksheetIndex parameters for narrowing down what you want to convert.
If you want to convert a range of sheets, you can only loop on the range, each time converting a separate PDF from one sheet at a time.
No better choice up until now.

How do I take a .csv file and add it as a worksheet to a PHPExcel object?

I create a sheet
$xls = new PHPExcel();
$xls->addSheet('my sheet');
I create an object to read a .csv
$objReader = PHPExcel_IOFactory::createReader('myfile.csv');
$objPHPExcel = $objReader->load($myFileName);
Is there a short way to place all the rows from the csv into the current worksheet?
The worksheet object has fromArray() and toArray() methods, so why not use those?
$xls->getActiveSheet()
->fromArray(
$objPHPExcel->getActiveSheet()->toArray()
);
Otherwise you can iterate over $objPHPExcel->getActiveSheet() reading cells, or rows at a time, then inserting them into $xls->getActiveSheet()

How to copy and paste indd file content into an another indd file?

I'm newbie in indesign scripting stuffs.So I apologise as I couldn't post my trials.
Objective:
I have an indd document which will have figure caption,label etc. I need to copy content(figure which is editable) from other indd file to this document where related figure label exists.
For example:
sample.indd
Some text
Fig.1.1 caption
some text
I need to copy the content of figure1.indd and paste into the sample.indd document where Fig.1.1 string exists and so on. Now I'm doing it manually. But am supposed to automate this.
So, I need some hint how to acheive it using extendscript?
I have found something like below to do this, but I don't have any clue to develop it further and also am not sure whether this approach is correct to get my result. Pls help me
myDocument=app.open(File("file.indd"),false); //opening a file to get the content without showing.
myDocument.pages.item(0).textFrames.item(0).contents="some text";
//here I could set the content but I don't knw how to get the content
// ?????? Then I have to paste the content into active document.
I found the script for my requirement.
var myDoc = File("sample.indd");//Destination File
var myFigDoc = File("fig.indd");//Figure File
app.open(File(myFigDoc));
app.activeDocument.pageItems.everyItem().select();
app.copy();
app.open(File(myDoc));
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "FIG. 1.1 ";//Figure caption text
//app.findGrepPreferences.appliedParagraphStyle = "FigureCaption";//Figure Caption Style
myFinds = app.activeDocument.findGrep();
for(var i=0;i<myFinds.length;i++){
myFinds[i].insertionPoints[0].contents="\r";
myFinds[i].insertionPoints[0].select();
app.paste();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
If acceptable for you, you can place an indesign file as link (place…). So a script could try to catch the "fig…" strings and do the importation.
Have a look at scripts that use finGrep() and place() command.

Error copying sheets in phpexcel

I am trying to extract some sheets in phpexcel as follows (see https://stackoverflow.com/a/10587576/813801 for reference).
$newObjPHPExcel = new PHPExcel();
$newObjPHPExcel->removeSheetByIndex(0); //remove first default sheet
foreach ($sheets as $sheetIndex) {
echo "trying-$sheetIndex\n";
$workSheet = $objPHPExcel->getSheet($sheetIndex);
echo "done-$sheetIndex\n";
$newObjPHPExcel->addExternalSheet($workSheet);
}
(sheets is an array of indexes which are within the bounds of the sheet. I checked with listWorksheetInfo)
If I comment out the the last line $newObjPHPExcel->addExternalSheet($workSheet);
The getSheet method works fine. Otherwise, I get an error:
Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Your requested sheet index: 2 is out of bounds. The actual number of sheets is 1.' in /Xls/PHPExcel/PHPExcel.php:577
Why should newObjPHPExcel interfere with objPHPExcel?
UPDATE:
I found a workaround which seems to work. not sure why the other version did not work though.
$newObjPHPExcel = new PHPExcel();
$newObjPHPExcel->removeSheetByIndex(0); //remove first default sheet
foreach ($sheets as $sheetIndex) {
echo "trying-$sheetIndex\n";
$workSheet[] = $objPHPExcel->getSheet($sheetIndex);
echo "done-$sheetIndex\n";
}
foreach ($workSheet as $obj)
$newObjPHPExcel->addExternalSheet($obj);
The addExternalSheet() method actually removes the worksheet from the old workbook and moves it to the new one, but your iterator over the old workbook collection of sheets still believes that it contains that worksheet when it no longer does.
In your second "workround" code, you're not removing the sheets from the old workbook until after you've completed iterating over the first loop, you're simply setting an array of pointers to the sheets, then iterating over that array, so the pointer array doesn't care that the sheets are being moved from one workbook to another, they all still exists, so no error.
An alternative might be to use the worksheet iterator against the old workbook, which should update cleanly as the sheets are removed.

Remove .js file works but a warning persist

i would like to remove a .js file from a drupal module to override this .js one in my theme.
So, in my MYTHEME_preprocess_page() function I added the following code:
//Delete logintoboggan.js and replace by our own in .info file
$tmpJs = drupal_add_js();
if (isset($tmpJs['module']['sites/all/modules/logintoboggan/logintoboggan.js'])) unset($tmpJs['module']['sites/all/modules/logintoboggan/logintoboggan.js']);
$vars['scripts'] = drupal_get_js($tmpJs);
This for, but a warning message appear on the website:
warning: Illegal offset type in isset or empty in /home/mykitxen/public_html/example.com/includes/common.inc on line 2210.
What is wrong?
You're missing the first parameter of drupal_get_js() ($scope), which should be 'header' or NULL in your case (with NULL just triggering the default 'header'). So the last line of your code should be:
$vars['scripts'] = drupal_get_js('header', $tmpJs);
or
$vars['scripts'] = drupal_get_js(NULL, $tmpJs);
NOTE: This assumes Drupal 6. If you are using Drupal 7, you might want to take a look at hook_js_alter().

Resources