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;
}
Related
I saw that there was a way to autofit rows in the worksheet. But I only want to autofit the rows that have only merged cells in it. And keep all of the other rows the same. Not sure if there is a way to do this.
I've tried this but it autofits all rows.
AutoFitterOptions options = new AutoFitterOptions();
options.AutoFitMergedCells = true;
_worksheet.AutoFitRows(options);
And I won't know the exact row that needs to be autofitted because I'm adding data to the excel sheet.
Please try the following sample code for your needs:
e.g.
Sample code:
Workbook wb = new Workbook("e:\\test2\\Book1.xlsx");
Worksheet _worksheet = wb.Worksheets[0];
var cells = _worksheet.Cells;
foreach (Cell cell in cells)
{
if (cell.IsMerged)
{
int row = cell.Row;
AutoFitterOptions options = new AutoFitterOptions();
options.AutoFitMergedCells = true;
_worksheet.AutoFitRows(row, row, options);
}
}
wb.Save("e:\\test2\\out1.xlsx");
Hope, this helps a bit.
You may also post your queries in dedicated forums.
PS. I am working as Support developer/ Evangelist at Aspose.
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.
I have used ClosedXML to create an excel file with 3 worksheets from AX 2012 R3.
I'm wondering if it is possible to use ClosedXML to read the excel file back in to AX?
Yes, that is possible.
Here is the sample code:
ClosedXML.Excel.XLWorkbook workbook;
ClosedXML.Excel.IXLWorksheet worksheet;
ClosedXML.Excel.IXLCells cellsUsed;
ClosedXML.Excel.IXLCell cell;
System.Collections.IEnumerator enumerator;
str value;
;
try
{
workbook = new ClosedXML.Excel.XLWorkbook(#"YourTestFile.xlsx");
worksheet = workbook.Worksheet("SomeEpicSheetName");
cellsUsed = worksheet.CellsUsed();
enumerator = cellsUsed.GetEnumerator();
while (enumerator.MoveNext())
{
cell = enumerator.get_Current();
value = System.Convert::ToString(cell.get_Value());
info(value);
}
}
catch
{
error(AifUtil::getClrErrorMessage());
}
This code creates a message in the InfoLog for each cell filled with a value. You can use it as a start in any new job after changing the used path and sheet name.
This is my example sheet:
The output:
I have an excel (xlsx) file that contains random columns. Some of these columns have formulas mapped to the sum of some cells; for example:
=J8+F9-H9
In my case I have the following three columns:
F: number
H: number
J: =sum of previous row's F and H cell's values.
I aim to get external data and store them cell by cell in this workbook. For this I am using Node module exceljs.
This is my code so far, I am harcoding values for now (which I will be getting from another file later on).
var workbook = new Excel.Workbook();
var filename = 'Bank Synoptic Journal.xlsx'
workbook
.xlsx
.readFile(filename)
.then(function() {
var worksheet = workbook.getWorksheet('Bank Synoptic');
var row = null;
row = worksheet.getRow(8);
row.getCell('J').value = Math.random();
row.commit();
for(var i=9; i<=305;i++) { //row
row = worksheet.getRow(i);
row.getCell('F').value = Math.random();
row.getCell('H').value = Math.random();
row.commit();
}
})
.then(function() {
return workbook.xlsx.writeFile(filename + '_modified.xlsx');
})
.then(function() {
console.log('Done!');
});
It prints the output into a new excel file. The problem I am facing is that for cells 'J' ie which contains the formulas; these cells are breaking with no consitency:
Some cells keep formulas and do the calculations
Others have no more formulas nor calculations done (have '0' instead of formula)
Recalculations are not done automatically using this injection mechanism
(Snapshots)
What I am missing or doing wrong that is leading to this error?
After several trials and errors I moved to Apache POI and so built the script using Java.
I downloaded and included the following JARs in my project:
It manipulates rows/columns and keeps the formulas intact. Once you open the modified excel file all you have to do is refresh (On Windows: ctrl + alt + f9) and it will recalculate.
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);