phpexcel fit to selection - phpexcel

I generate an excel file using the great PHPExcel library. At this moment I need to show all the columns into a single page. You know the feeling when you have to scroll left and right up and down to see all the data. Basically I have 33 columns and I need to fit them on any display
I don't know if is my setup or where is the problem, but I can't make it work. This is the code I'm using
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(true);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
On MS Excel I select all thw colums then I choose View-> Zoom, then select Fit Selection. How can I do that programatically when excel file is generated with PHPExcel.

i hope i don't understand you wrong, here it goes:
phpExcel has an method called setZoomScalezoom(), however this does not auto fill the whole screen:
example:
$excel = new PHPExcel();
$sheet = $excel->getActiveSheet();
$sheet->getSheetView()->setZoomScale(300);
$writer = new PHPExcel_Writer_Excel5($excel);
$writer->save('test.xls');
got my information from:
source: http://typo3.org/extension-manuals/phpexcel_library/1.7.4/view/5/4/
Setting worksheet zoom level To set a worksheet’s zoom level, the
following code can be used:
$objPHPExcel->getActiveSheet()->getSheetView()->setZoomScale(75);
Note that zoom level should be in range 10 – 400.

Related

Adafruit MagTag: Dither a jpg from placekitten.com and display on MagTag

Pimoroni has an example that grabs a jpg online and displays it on one of their Inky e-ink displays.
I am wondering if it is possible to do the same thing with an Adafruit MagTag using CircuitPython. In the latest version of CircuitPython, there are BitmapTools that seem like they may be able to convert a .jpg file into a .bmp that is dithered appropriately for an e-ink display. There just doesn't seem to be any example code that shows how to do this.
Is it possible?
Any examples of using bitmaptools.dither(dest_bitmap: displayio.Bitmap, source_bitmapp: displayio.Bitmap, source_colorspace: displayio.Colorspace, algorithm: DitherAlgorithm = DitherAlgorithm.Atkinson)→ None
The code would look a little like this ...
import board
import displayio
import adafruit_imageload
display = board.DISPLAY
bitmap, palette = adafruit_imageload.load("/purple.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
# Create a Group to hold the TileGrid
group = displayio.Group()
# Add the TileGrid to the Group
group.append(tile_grid)
# Add the Group to the Display
display.show(group)
# Loop forever so you can enjoy your image
while True:
pass
... but we would pull in a .jpg and have to do a little work on it so that the greyscale image becomes a dithered .bmp.
Any ideas?
I can pull in a .jpg. I just can't process it and display.
I was also looking for an API or something that might be able to pre-process the image from https://placekitten.com so that it would already be a dithered bitmap file. Does that exist?

R View gt table in window from script message box three buttons

Ultimate goal: Display gt table in pop-out window with 3 buttons to control script action
Minimum goal: Display a gt table in pop-out viewer window
Full detail:
I am creating a table using the gt package in R. I want to display the table with three options for how to proceed: OK (script continues), Edit (allow the user to make minor modifications to a specific column), Cancel (something has gone wrong and the process needs to be terminated). My plan is to allow a quick QC of the data before it gets saved. My issue is that I have no idea how to display a gt table in a viewer window or with tk_messageBox and that's about the only package I know of that might do this.
Any ideas?
Here's an example gt table:
table <- gt(mtcars) %>%
tab_header(
title = md("**2014 - 2019 Salary and Playoff Appearances**⚽"),
subtitle = "I am a boss")
you could achieve such an effect with shiny/miniUI specifically runGadget()
see this answer I gave yesterday which is an example where the user is shown two checkboxes to interact with that are returned as data into the calling environment
Is it possible to create a check box to record a user's input without resorting to Shiny in R?

How to modify the DataLabel fill (using a solid fill color)?

I'm trying to edit the data labels for a chart I'm writing on the slide. I can access the text of the datalabel using the methods available but as of yet the datalabel.fill is not existent. Any workarounds welcome if this is not planned on being added to the library in the future.
I've already gone through the source code in the github (https://github.com/scanny/python-pptx) but the datalabel class only has the font, has_text_frame, position, text_frame, _dLbl, _get_or_add_dLbl, _get_or_add_rich, _get_or_add_tx_rich, _get_or_add_txPr, and _remove_tx_rich methods. No fill or line fill methods is available.
The script I'm running does something similar for cells in a table:
cell.fill.solid()
cell.fill.fore_color.rgb = color_list[((col>0)*1)][i%2]
I'm looking at replicating the functionality on datalabels for chart series, with code that looks like this:
label.fill.solid()
label.fill.rgb = RGBColor(0x9B,0xBB,0x59)
label.fill.alpha = Alpha(.2)
label.line.fill.solid()
label.line.rgb = RGBColor(0xF0,0xF0,0x00)
The expected output xml should put the following for data labels:
<c:spPr>
<a:solidFill>
<a:srgbClr val="9BBB59">
<a:alpha val="80000"/>
</a:srgbClr>
</a:solidFill>
<a:ln>
<a:solidFill>
<a:schemeClr val="F0F000"/>
</a:solidFill>
</a:ln>
</c:spPr>
Actual output is non-existent as there is no method to do this directly.
This feature is not yet implemented, but if it was implemented it would be a .format property on the DataLabel object.
Typically users will work around an API gap like this by adding what we typically call a "workaround function" to the client code that manipulates the underlying XML directly, in this case, to add an <c:spPr> subtree in the right place.
python-pptx can generally get you close as far as a parent element is concerned. In this case, it can get you to the <c:dLbl> element like this:
data_label = chart.series[0].points[0].data_label
dLbl = data_label._dLbl
print(dLbl.xml)
The leading underscore in ._dLbl is your hint that you're getting into internals and if things don't go well it's something you're doing wrong, not an issue to be reported.
The dLbl object is an lxml.etree._Element object and can be manipulated with that API. If you have a search on "python-pptx workaround function" you'll find some examples for how to create new elements and put them where you want them.
The .xml property available on any python-pptx XML element object is handy for inspecting the results along the way. opc-diag can also be handy for inspecting PPTX files generated by PowerPoint or python-pptx for analysis or diagnostic purposes.

Writing Comments (metadata) within image file using R

I would like to add parameter information to the plots that we make as part of our research project. I know that png has a text block for adding comments. (I am not a png expert, but I think it uses the tEXt block.) Using Gimp, under image properties, you can add a comment that can be read by other software (e.g. by the "inspector" in mac preview. I'm sure there is a windows equivalent). We make our images with ggsave. I did not see any arguments to ggsave that allows us to write to the "comment" block of a png file. I've tried using png::readPNG, and png::writePNG functions
im <- readPNG("test1.png",native=FALSE,info=TRUE)
md <- c(comment=paste0(date=date(),machine=Sys.info()['nodename']))
writePNG(image=im,target="test1_md1.png",text=md,metadata = md)
im2 <- readPNG("test1_md1.png",native=FALSE,info=TRUE)
attr(img2, "info")
I can open the new png file, it looks just like the old one. However, the comment block is not filled. As you can see, the data is written in the file, but neither gimp nor preview can read it. Is there a way to write the metadata in the comment block so that preview and gimp can read it correctly?
Thank you
update: ok, png::writePNG does actually write into the tEXt block, however neither gimp nor preview read the text block. I wrote a simple java program that reads the blocks.
IHDR null javax.imageio.metadata.IIONamedNodeMap#133314b
width = 2580 height = 1800 bitDepth = 8 colorType = RGBAlpha compressionMethod = deflate filterMethod = adaptive interlaceMethod = none
tEXt null javax.imageio.metadata.IIONamedNodeMap#b1bc7ed
tEXtEntry null javax.imageio.metadata.IIONamedNodeMap#7cd84586
keyword = date value = Tue Dec 4 12:55:45 2018
tEXtEntry null javax.imageio.metadata.IIONamedNodeMap#30dae81
keyword = machine.nodename value = mycomputer.xyz.org
Is there a separate comment block somewhere? That is the block I want to write to.
update 2: It appears that gimp/preview read the iTXt block. So the question becomes can I write to the iTXt block from R.

R - ReporteRs package - word template with dynamic values

good day people,
I'm working on a word based reports automation task. These reports are basically some standard text, a dozen or so charts, some numeric/trend text values that I need to populated based on logic. The trend text, numeric values or charts are to be generated from backend database.
I'm able to produce a blank document with charts using database, the R packages I used are ReporteRs, RODBC, officer and corresponding dependency packages, ggplot2 for charts.
However what I would like to achieve is, have a word document template with some sort of placeholders where I can put the charts and these numeric values.
I've basic code as following
doc <- docx(title="my doc")
mychart <- ggplot(.....)
doc <- addPlot(doc, fun=print, x = mychart)
writeDoc(doc, filename)
Can anyone advise how to approach this task. I saw usage of template parameter in docx but I couldn't find suitable examples of putting values in placeholders or putting charts at particular placeholders inside Word document.
Hope I've explained it clearly, if not please let me know.
Ok I've figured out how to achieve it finally.
MS-Word allows putting placeholders in document and bookmark them so that values/data/images can be put in their place.
You can create a normal word document(not as word template) and add your static content in it along with bookmarked placeholders as per your requirements.
Please refer here to know how to add bookmarks , Word doesn't show existing bookmarks by default, to enable that go to File -> Options -> Advanced check Show bookmarks, you'll see [your_bookmark] thing in square brackets.
Next in R, try following code
doc <- docx(title="title", template="c://above_template.docx")
doc = addPlot(doc, x=myChartVariable, bookmark="your_chart_bookmark)
writeDoc(doc, "c://new_doc_file_path.docx:)
you should see new file with a chart substituted where you put its placeholder.
I would recommend using VBA for this, not R. Do some google-research on DocVariables in Word. Add some DocVariables to your Word template, keep your analytics in Excel, and then push what you have in Excel into the Word DocVariables. Use the script below, which runs in Excel, to make everything work.
Sub PushToWord()
Dim objWord As New Word.Application
Dim doc As Word.Document
Dim bkmk As Word.Bookmark
sWdFileName = Application.GetOpenFilename(, , , , False)
Set doc = objWord.Documents.Open(sWdFileName)
'On Error Resume Next
objWord.ActiveDocument.variables("BrokerFirstName").Value = Range("BrokerFirstName").Value
objWord.ActiveDocument.variables("BrokerLastName").Value = Range("BrokerLastName").Value
objWord.ActiveDocument.variables("Ryan").Value = Range("Ryan").Value
objWord.ActiveDocument.Fields.Update
'On Error Resume Next
objWord.Visible = True
End Sub
Finally, add a reference to Word, from Excel. Tools > References > Microsoft Word xxx Object Library.

Resources