Hidden Cells still showing in an OfficeWriter Excel Spreadsheet - excel

When my Office Writer Excel report opens, it randomly un-hides some of the hidden cells and columns. I have verified that it is not the data that causes the columns or cells to not be hidden. Has anyone experienced this before and is there a way to make sure that all columns or cells stay hidden when the excel file is opened?

I work for SoftArtisans. We have not had any other reports of programmatically hidden columns becoming visible in the output file. We also have not been able to reproduce the behavior you are reporting. It would be helpful to see a code snippet, as well as to know which version of OfficeWriter you are using and which version of Excel is being used to open the output file.
There are two ways to hide columns with our API, both using the ColumnProperties object. You can set the hidden property to true or set the width property to zero. You could do both if you like, although that shouldn't be necessary.
For example:
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx);
//or if opening an existing workbook
//Workbook wb = xla.Open(inputFilePath);
//Get a handle on the worksheet
Worksheet ws = wb.Worksheets[0];
//Write a value to a cell
ws.Cells[0, 9].Value = "Hidden Value";
//Get a handle on the column you want to hide
ColumnProperties colProps = ws.GetColumnProperties(9);
//set the column to hidden
colProps.Hidden = true;
//or set the column width to zero
colProps.Width = 0;
//Stream the output file to the response
xla.Save(wb, Page.Response, "HiddenColumnTest.xlsx", false);

Related

How to update the source data range for existing chart

I'm trying to write a script that finds data in a sheet dynamically (the dimensions of the table need to be flexible in both axis) and then updates the source data range for an existing chart on another sheet (so that my users don't need to set up the styling themselves).
Below is my script so far. Everything works apart from the final line where Excel Online gives me the error:
"Line 10: Chart setData: You cannot perform the requested operation"
function main(workbook: ExcelScript.Workbook)
{
let selectedSheet = workbook.getWorksheet("Enter data in this sheet");
// Add a new table at used range on selectedSheet
let range = selectedSheet.getUsedRange();
if(selectedSheet.getTables().length == 0)
{
let newTable = workbook.addTable(range, true);
}
workbook.getWorksheet("The Chart").getChart("Chart 1").setData(range);
}
The worksheet names are correct and so is the chart name as far as I can see:
screenshot of excel online showing chart and worksheet names
Answer found; the chart was on a protected sheet which did not allow editing of objects. Updating the protection to allow all users to edit objects has resolved the issue.

Why is my Excel file empty after writing content to cells using Microsoft.Office.Interop.Excel?

I'm using Microsoft.Office.Interop.Excel to write an Excel file. The code below is not working:
var excel = new Microsoft.Office.Interop.Excel.Application();
var workbook = excel.Workbooks.Add(Type.Missing);
var worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;
worksheet.Name = "sheet1";
worksheet.Cells[1,1] = "top left";
worksheet.Cells[1,2] = "top right";
worksheet.Cells[2,1] = "bottom left";
worksheet.Cells[2,2] = "bottom right";
workbook.SaveAs("temp.xlsx");
workbook.Close();
excel.Quit();
It produces an Excel file but it is empty. I'm expecting to see the text "top left", "top right",... in the first 2 by 2 cells. But I see nothing.
Why is it not writing content to my worksheet?
You can find my code at github: https://github.com/gibran-shah/Image2Excel
Perhaps this link might help you: http://csharp.net-informations.com/excel/csharp-create-excel.htm
According to the link above, try using:
var worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.get_Item(1);
To troubleshoot further, I would choose some other name for the sheet, and check that the name is actually being set by opening the workbook and observing the name in the sheet's tab. This would ensure you are indeed adding data to the sheet that you think you are.

How to edit specific excel sheet

I have a maser sheet containing multiple sheets. I want to editing DATA sheet shown in the image and I can edit but when i edit the DATA sheet then the data and pivot tables and styling and formatting in Main repot and pivot sheets gets blank . how to stop being formatting and styling gets blank.
I am using laravel with maatwebiste.
below is the originalsheet
but when i store and download the updated sheet the sheet gets blank
this is data sheet
Excel::selectSheetsByIndex(2)->load($final_file_path, function($reader) {
$reader->sheet('Data', function($sheet) {
$select_arrays = ['85213','Age','40-49','2019-12-01','111111','Not Stated','Not Stated'];
$sheet->appendRow($select_arrays);
}, 'UTF-8')->store('xlsx', storage_path('/'), true);
Above code is working fine but when store to the path all formatting pivots are removed
Earlier I was using maatwebiste that does not support Pivot but now in my solution I used COM library used for excel.
Converting excel to pdf using PHP
The solution for the above problem mentioned below:-
// WORKBOOK AND WORKSHEET OBJECTS
$wbk = $xlapp->Workbooks->Open("C:\\xampp\htdocs\php-excel1\PivotReportMockUp.xlsx");
$wks = $wbk->Worksheets(2);
$wks1 = $wbk->Worksheets(1);
// SET CELL VALUE
$wks->Range("B2")->Value = "85552";
$wbk->save();
// OUTPUT WORKSHEET TO PDF
$xlTypePDF = 0;
$xlQualityStandard = 0;
$OpenAfterPublish= True; //`enter code here`
$IgnorePrintAreas = True;
try {
$wks1->ExportAsFixedFormat($xlTypePDF, "C:\\xampp\htdocs\php-excel1\PivotReport.pdf", $xlQualityStandard,$OpenAfterPublish,$IgnorePrintAreas);
} catch(com_exception $e) {
echo $e->getMessage()."\n";
exit;
}

Disable Excel Error Checking through Coldfusion

I enforced the number having leading zero to the text .
It is working well but it is showing green icon on the corner on clicking it displays the error .
My question is that how i can stop or disable this button not to show on the excel sheet programmatically.
In excel sheet you can easily disable error checking but i want this through code
Any Help will be appreciated
Thanks!
Short answer:
The ability to suppress Excel's error checking on a cell level is supported in POI 3.14+. See below details. The other option is to leave the cells as numeric, but apply a mask with leading zeroes, ie: SpreadSheetFormatCell(sheet, {dataFormat="00000"}, row, column).
Longer answer:
After a bit of reading, it turns out the ability to suppress this error was added in POI 3.14. Unfortunately, CF11 is bundled with an older version, 3.9. However, you can access the newer functionality by loading POI 3.14 (or later) using this.javaSettings in your Application.cfc, along with a bit of java code.
Start by creating the spreadsheet as usual:
// format a few cells as text, then add values with leading zero
cfSheet = SpreadSheetNew("Test", true);
SpreadSheetFormatCell(cfSheet, {dataFormat="#"}, 1, 1);
SpreadSheetSetCellValue(cfSheet, "01234", 1, 1);
SpreadSheetFormatCell(cfSheet, {dataFormat="#"}, 1, 2);
SpreadSheetSetCellValue(cfSheet, "05678", 1, 2);
In order to manipulate the spreadsheet with the newer classes, it must be read into a new Workbook object using the POI WorkbookFactory. The factory supports loading from both a physical file OR a stream of bytes. (For brevity, I will use bytes).
// load workbook from byte array
bytes = SpreadsheetReadBinary( cfSheet );
stream = createObject("java", "java.io.ByteArrayInputStream").init(bytes);
factory = createObject("java", "org.apache.poi.ss.usermodel.WorkbookFactory");
wb = factory.create(stream);
// grab reference to our worksheet
jSheet = wb.getSheet("Test");
Next create a range object representing the cells where you want to suppress the "number as text" error. Then add the range to the list of ignored errors in the sheet.
// Create range of cells containing numbers as text
CellRange = createObject("java", "org.apache.poi.ss.util.CellRangeAddress");
rangeToModify = CellRange.valueOf("A1:A2");
// Flag the range to ignore "number as text" error
IgnoreTypes = createObject("java", "org.apache.poi.ss.usermodel.IgnoredErrorType");
jSheet.addIgnoredErrors(rangeToModify, [ IgnoreTypes.NUMBER_STORED_AS_TEXT] );
Finally, save the updated workbook to a file:
// Save to disk
fos = createObject("java", "java.io.FileOutputStream").init("c:/path/uniqueName.xlsx");
wb.write(fos);
fos.close();

How to add more than 3 sheets to an excel workbook from within MATLAB

How do I add more sheets to an excel workbook from within matlab?
I set up the workbook like so (based on code I got from someone else's post in this forum):
%# create Excel COM Server
Excel = actxserver('Excel.Application');
Excel.Visible = true;
%# create new XLS file
wb = Excel.Workbooks.Add();
wsheet=1;
wb.Sheets.Item(wsheet).Activate();
That's fine. Then later on inside the loop I open a new sheet after so many loops:
...
if loop==sheetlimit,
wsheet=wsheet+1;
wb.Sheets.Item(wsheet).Activate();
end
This works up to sheet 3. But when wsheet=4 I get this error message:
??? Invoke Error, Dispatch Exception: Invalid index.
Error in ==> filename at 97
wb.Sheets.Item(wsheet).Activate();
Appreciate any help. Thanks.
I don't know Matlab but I would be surprised if wb.Sheets.Item(wsheet).Activate(); is actually adding any new worksheets. Most likely it is selecting / activating each worksheet in your wb workbook and your default Excel template has three worksheets. Hence why it errors when it gets to more than three.
Something like this might add a new Excel worksheet:
wb.sheets.Add();
Aargh - comment formatting completely messed up - I'll re-enter it as an new answer
Yes wb.sheets.Add(); will work. You can query the available methods of an interface like this:
methods(wb.sheets)
which gives:
Methods for class Interface.000208D7_0000_0000_C000_000000000046:
Add FillAcrossSheets PrintOut addproperty events loadobj set
Copy Item PrintPreview delete get release
Delete Move Select deleteproperty invoke saveobj

Resources