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.
Related
const Excel = require('exceljs');
let workbook = new Excel.Workbook();
let workSheet = workbook.getWorksheet(1);
workSheet.getCell('W2').font = {color: {argb: "004e47cc"}};
this code sets font color for entire row, not just W2 cell. Same happens if I do:
let row2 = workSheet.getRow(2);
row2.getCell(23).font = {color: {argb: "004e47cc"}}; //W2
So how do I set cell style just for certain cell?
It worked for me as well, but your code doesn't work as-is. workbook.getWorksheet(1) is failing, since you haven't created any worksheets in the new workbook you created.
This code generates a valid .xlsx file where cell W2 has the color you want:
const Excel = require('exceljs');
const workbook = new Excel.Workbook();
const workSheet = workbook.addWorksheet('Sheet');
workSheet.getCell('W2').font = {color: {argb: "004e47cc"}};
workbook.xlsx.writeFile('foo.xlsx');
Use "getWorksheet('sheetName')" instead of "getWorksheet(sheetNo)", This works fine for me.
About styling:
This one should work properly:
row2.getCell(23).style = {font:{color: {argb: "004e47cc"}}}
Because, as a default all cells in a row referencing into one style object and the font is only a getter and setter to .style.font
About accessing into worksheet:
Use "getWorksheet('sheetName')" instead of "getWorksheet(sheetNo)", This works fine for me.
So, in exceljs we provide two ways to get worksheet:
// FIRST:
// wb.getWorksheet(ws:string|number):Worksheet
wb.getWorksheet('sheetName')
wb.getWorksheet(sheetId)
// NOTE: sheetId is number written into worksheet,
// it's not a index in array - just a number from Excel.
// So for some files you read sheetId may be for instance: 10, 9, 999
// I recommend to avoid using ws.getWorksheet(NUMBER).
// SECOND:
// wb.worksheets: Array<Worksheet>
wb.worksheets[1];
wb.worksheets[2];
wb.worksheets[wb.worksheets.lenght-1];
// I am big fan of using this way :)
I have issue with protect worksheet in excel online. I will unlock all of the cells in the worksheet, and lock one range, then protect worksheet, after that nothing is editable in the worksheet, even the cells are unlocked.This issue only happens for excel online version, works fine for installed desktop version. Anyone has idea how to solve the problem or the is an officeJs bug?
Excel.run(function (ctx) {
//Worksheet
var sheet = ctx.workbook.worksheets.getItem("Sheet1");
//Entire Range
var entireRange = sheet.getRange();
entireRange.format.protection.locked = false;
//Specific Range
var range = sheet.getRange("A1:B5");
range.format.protection.locked = false;
//Protect Entire sheet
sheet.protection.protect({
allowInsertRows: false,
allowDeleteRows: false
});
return ctx.sync();
}).catch(errorHandler);
This should be an issue of Office-Js API.
We Office-Js API team are looking into this issue.
We are tracking it by internal bug 2542108.
The worksheet will recover to editable state when user refreshes the page. I'm afraid there's no workaround you can do from API side currently.
the issue is fixed now, this should no longer happen.
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);
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.
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);