Hi,
I would like to align all my content towards left in a specific sheet. How is it achievable.
I tried searching the documentation and got to know that it is only applicable at the cell level and not at the worksheet level.
Can you please specify which version of Aspose.Cells you are using and if you are looking for a specific programming language for the solution?
@shreyap
Please use Cells.ApplyStyle method as the following :
Style style = workbook.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Left;
StyleFlag flag = new StyleFlag();
flag.HorizontalAlignment = true;
workbook.Worksheets[0].Cells.ApplyStyle(style, flag);
@simon.zhao,
Some of the columns are not aligning towards left event after applying above styles.
Attaching you the file for reference.
TA.zip (56.3 KB)
Thanks for the sample file.
I checked the alignment settings of the column cells and found all of them are aligned to Left (In MS Excel, right click on any cell of the second worksheet and click “Format Cells…” to open the dialog. In the Alignment tab, check “Text alignment” which is “Left (Indent)” for horizontal alignment settings). I think you are talking about “Unit Cost” and “Total” columns. You may check alignment settings for the columns cells and you will found these are Left (horizontally) alignment which is OK. Could you please change the alignment settings for these columns cells in MS Excel manually? Please provide your expected file having these columns alignment settings with your desired (horizontally) aligned. We will check it soon.
@shreyap
Do you mean the column E and F in the worksheet SalesOrders?
The number format is (* #,##0.00);(* (#,##0.00);(* “-”??);(@_) , so some spaces will be filled util the text align right.
@amjad.sahi , Thanks for the reply. I guess @simon.zhao answered my question.
@simon.zhao , Can you please help me understand the format. And also how do I check that column is in such specific format and that is the reason it is not aligning to left even after manual selection.
This would be of great help. Thank you!
@shreyap
1). For example: (* #,##0.00);(* (#,##0.00);(* “-”??);(@)
"* " means fill spaces , then all number values align right.
")" leaves a gap which width is same as “)”
2). There is no method to change whole column according to the number format, please iterate all cells by yourself:
Cells cells = workbook.Worksheets[1].Cells;
for(IEnumerator ie = cells.GetEnumerator(); ie.MoveNext();)
{
Cell cell = (Cell)ie.Current;
Style style = cell.GetStyle();
string custom = style.Custom;
if(custom.IndexOf("* ") != -1)
{
custom = custom.Replace("* ", "");
style.Custom = custom;
cell.SetStyle(style);
}
}
The above codes is a sample. But sometime the number format is complex, simple replace will corrupt the number format. so please replace number format carefully.