Make Excel Sheet With Multiple Ultra Win Grid (UltraGridExcelExport) - excel

Dear All Friends
I Have One Window Form Which Have 5 Grid Of Infragistics Ultra Grid. I Want To Export All Grid TO Excel File. Now Problem Is That. In Need All 5 Grids In On Sheet As Shown As Form. So Please Help To Solve.
Currently I Export Only One Grid To Excel Using Infragistics Inbuild Method
UltraGridExport.Export(UltraGrid,FileName)
Suggest Me With Multiple Grid Export In One Sheet.
Thank To All.

How about exporting the results into multiple sheets on the workbook?
Create a workbook and then for each grid create a worksheet on the workbook and then export the grid to the worksheet.
public static void ExportToExcel<T>(this IEnumerable<T> grids, string filename)
where T : UltraGrid
{
Workbook workbook = new Workbook();
UltraGridExcelExporter exporter = new UltraGridExcelExporter();
foreach (T g in grids)
{
Worksheet sheet = workbook.Worksheets.Add(g.Name);
exporter.Export(g.GridControl, sheet);
}
workbook.Save(filename);
}

string StrFile = Application.StartupPath + "\\EmpLevDetView.xls";
Workbook WB = new Workbook();
WB.Worksheets.Add("Detail");
ExcelExport.Export(UltGrdDet, WB.Worksheets["Detail"], 0, 0);
WB.Worksheets.Add("Summary");
ExcelExport.Export(UltGrdSum, WB.Worksheets["Summary"], 0, 0);
BIFF8Writer.WriteWorkbookToFile(WB, StrFile);
System.Diagnostics.Procesenter code heres.Start(StrFile);

Related

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;
}

Aspose.cells and aspose.slides

I am totally new to aspose. kindly help me to achieve the below requirement.
Requirement:- I am trying to make an application which can process an excel file and based on the excel data application will generate an output file( ppt extension).
Special instruction:- Please make a note I will provide ppt template and that template will have a certain placeholder where data will be inserted from uploaded excel.
Work In Progress:-
I have added both Aspose.Cells and Aspose.Slides dll to my project and wrote below PoC.
private void button1_Click(object sender, EventArgs e){
Workbook wb = new Workbook(#“C:\Users\Nilanjan\Desktop\Incident.xlsx”);
Worksheet ws = wb.Worksheets[0];
Cells cells = ws.Cells;
int col = CellsHelper.ColumnNameToIndex(“N”);
int last_row = ws.Cells.GetLastDataRow(col);
DataTable dt = wb.Worksheets[0].Cells.ExportDataTable(0, 0,
wb.Worksheets[0].Cells.MaxDataRow + 1, wb.Worksheets[0].Cells.MaxDataColumn + 1);
Presentation ps = new Presentation();
ISlide slide=ps.Slides[0];
slide=ps.Slides[1];
ps.Save(#“C:\Users\Nilanjan\Desktop\CocoonIncident1.pptx”,Aspose.Slides.Export.SaveFormat.Pptx );
}
Till now I have tried to upload the excel into my code and after processing it I was able to fill a DataTable with the excel data, now next step is to fill the ppt-template with that DataTable data. Please help me to achieve this functionality or please suggest a suitable workaround. Let me know if ppt template or excel file is required.
#Nilanjan,
I have observed your requirements for adding DataTable to PowerPoint slides. There is no direct way available to add DataTable in PowerPoint slides. You need to access every cell in DataTable and add that in PowerPoint slides by following mechanism supported by PowerPoint or Aspose.Slides. I suggest you to please try using following sample code on your end.
public static void DataTableToSlides()
{
String path = #"C:\Aspose Data\";
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Term", typeof(string));
table.Columns.Add("Value", typeof(float));
table.Rows.Add(#"Term 16", 1.5);
table.Rows.Add(#"Term 15", 0.7);
table.Rows.Add(#"Term 14", 0.7);
table.Rows.Add(#"Term 13", 0.6);
table.Rows.Add(#"Term 12", 0.6);
Presentation pres = new Presentation();
ISlide slide = pres.Slides[0];
double[] colWidth = { 100, 100 };
double[] rowHeight = { 40};// 40, 40,40,40,40 };//1 row additional to hold the headers
ITable slidesTable = slide.Shapes.AddTable(100, 10, colWidth, rowHeight);
slidesTable[0, 0].TextFrame.Text = table.Columns[0].ColumnName;
slidesTable[1, 0].TextFrame.Text = table.Columns[1].ColumnName;
for (int i=0;i<table.Rows.Count;i++)
{
DataRow row = table.Rows[i];
slidesTable.Rows.AddClone(slidesTable.Rows[0], false);
slidesTable[0, i + 1].TextFrame.Text = row[0].ToString();
slidesTable[1, i + 1].TextFrame.Text = row[1].ToString();
}
pres.Save(path + "Saved.pptx",Aspose.Slides.Export.SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
Many Thanks.

Make a WordArt not recieve focus

Is there an API in VSTO/VBA for Excel or Aspose Cells for Java to make it so that a WordArt I added to the Excel worksheet never receives keyboard or mouse focus?
For e.g. in the picture below, when I click on the WordArt, it receives focus. When it has focus and I hit the Tab key on the keyboard, the focus goes to the next WordArt, i.e. the one above it.
I'd like these WordArt objects never to receive keyboard or mouse focus. Is there a way?
This can be achieved by protecting your worksheet. You can learn from internet how to protect worksheet and its contents or objects. Aspose.Cells supports the protection of worksheet.
Please see the following sample code which uses Aspose.Cells APIs. It explains how to protect your worksheet contents or objects. Please modify the code as per your needs.
Both Java and C# codes are given for a reference.
Java
//Load your workbook
Workbook wb = new Workbook("sample.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Unlock all cells of your worksheet
Style st = ws.getCells().get("A1").getStyle();
st.setLocked(false);
StyleFlag flg = new StyleFlag();
flg.setLocked(true);
ws.getCells().applyStyle(st, flg);
//Specify protection types
Protection p = ws.getProtection();
p.setAllowEditingContent(false);
p.setAllowEditingObject(false);
p.setAllowEditingScenario(false);
//Protect the worksheet
ws.protect(ProtectionType.ALL);
//Save the workbook
wb.save("output.xlsx");
C#
//Load your workbook
Workbook wb = new Workbook("sample.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Unlock all cells of your worksheet
Style st = ws.Cells["A1"].GetStyle();
st.IsLocked = false;
StyleFlag flg = new StyleFlag();
flg.Locked = true;
ws.Cells.ApplyStyle(st, flg);
//Specify protection types
Protection p = ws.Protection;
p.AllowEditingContent = false;
p.AllowEditingObject = false;
p.AllowEditingScenario = false;
//Protect the worksheet
ws.Protect(ProtectionType.All);
//Save the workbook
wb.Save("output.xlsx");
Note: I am working as Developer Evangelist at Aspose
Well, in Aspose.Cells APIs, you may try using certain locking attributes of the wordart shape to accomplish your task, see the sample code for your reference:
e.g
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL", "Open Sans", 50, false, true, 18, 8, 1, 1, 130, 800);
//Lock Shape Aspects.
wordart.setLocked(true);
wordart.setLockedProperty(ShapeLockType.SELECTION, true);
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true);
wordart.setLockedProperty(ShapeLockType.MOVE, true);
wordart.setLockedProperty(ShapeLockType.RESIZE, true);
wordart.setLockedProperty(ShapeLockType.TEXT, true);
FillFormat wordArtFormat = wordart.getFill();
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getLightGray());
wordArtFormat.setTransparency(0.55);
wordart.setHasLine(false);
workbook.save("out1.xlsx");
Hope, this helps a bit.
I am working as Support developer/Evangelist at Aspose.

Hidden Cells still showing in an OfficeWriter Excel Spreadsheet

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);

How to disable gridlines in Excel using open xml C#?

I want to disable GridLines in excel and put custom borders to excel cells using open xml in C#
I have tried with below code but is throwing exception when i open the excell,
the exception is "Repaired Part: /xl/worksheets/sheet.xml part with XML error. Load error. Line 1, column 0."
using (SpreadsheetDocument xl = SpreadsheetDocument.Create(sFile, SpreadsheetDocumentType.Workbook))
{
WorkbookPart wbp = xl.AddWorkbookPart();
WorksheetPart wsp = wbp.AddNewPart<WorksheetPart>();
Workbook wb = new Workbook();
FileVersion fv = new FileVersion();
fv.ApplicationName = "Microsoft Office Excel";
Worksheet ws = new Worksheet();
SheetViews sheetViews = new SheetViews();
SheetView sheetView = new SheetView();
sheetView.ShowGridLines = new BooleanValue(false);
sheetViews.Append(sheetView);
ws.Append(sheetViews);
WorkbookStylesPart wbsp = wbp.AddNewPart<WorkbookStylesPart>();
//// add styles to sheet
wbsp.Stylesheet = CreateStylesheet();
wbsp.Stylesheet.Save();
//// add styles to sheet
////wbsp.Stylesheet = GenerateStyleSheet();
//wbsp.Stylesheet.Save();
Columns columns = new Columns();
columns.Append(CreateColumnData(1, 1, 25));
ws.Append(columns);
//// generate rows
SheetData sd = CreateSheetData(products);
ws.Append(sd);
wsp.Worksheet = ws;
wsp.Worksheet.Save();
MERGEiNITIALcELLS(wsp);
wb.Append(fv);
CreateSheet(wbp, wsp, wb);
xl.WorkbookPart.Workbook = wb;
xl.WorkbookPart.Workbook.Save();
xl.Close();
The WorkbookViewId property of the SheetView class is a required attribute/property. Try this:
SheetView sheetView = new SheetView();
sheetView.ShowGridLines = new BooleanValue(false);
sheetView.WorkbookViewId = 0;
sheetViews.Append(sheetView);
ws.Append(sheetViews);
That uses the 1st (default) workbook view. Don't worry, you don't have to explicitly create a WorkbookView child of the BookViews class, which is a child of Workbook. Unless you want to, of course. :)
I tried this way but it was failing but able to identify what is missing. By default when creating a spreadsheet from scratch, there is no default workbook view. So need to create new workbook view.
spreadSheet.WorkbookPart.Workbook = new Workbook(new BookViews(new WorkbookView()));
Then create sheet view.
worksheetPart.Worksheet = new Worksheet(new SheetViews(new SheetView(){WorkbookViewId=0,ShowGridLines=new BooleanValue(false)}), new SheetData());
NOTE: When create columns in the excel workbook, the elements should be created in a sequence. The sequence is
Sheet Views
Sheet View Formatting
Columns
Sheet Data
Enjoy Open XML SDK but Microsoft does not provide very powerfull documentation.

Resources