OpenXML spacing troubles - c#

I am creating a word document(2010) using c#.
It consists of a large table weith cells and within the cells paragraphs.
I Have achieved this with a little with (i hope simple) a little niggly issue. In front of every piece of text there is a block of empty space.
I am attempting to get rid of this space with no luck.
To build the table I have pretty much followed this example.
http://msdn.microsoft.com/en-us/library/office/gg490656.aspx
I have tried fiddling with the sacing of the cells, of the table rows and of the table cells but i'm unsure if i am using the right properties.
I have tried appending new ContextualSpacing() { Val = false } to table row and cells with no luck. I've also tried new Spacing with no luck either!
Any ideas hints tips would be muchly appreciated

I found that setting the style to a style within word resolved the issue. This was a manual process and then i looked in to how to do this programatically.
DocumentFormat.OpenXml.Wordprocessing.TableStyle tableStyle2 = new DocumentFormat.OpenXml.Wordprocessing.TableStyle() { Val = "TableGrid" };
Append this item to the table and it all worked perfectly!

Related

Gembox Spreadsheet - Remove blank pages

I dont know how achieve this, I have to create an informative report with images. For this, I use an excell template (It helps me with the format and with the position of the text where to place the respective information). The images are generated perfectly. I convert this XLS to PDF with the property
DocumentToMemoryStream (excelTemplate, XlsxSaveOptions.XlsxDefault);
This report generate blank pages in the PDF. How can I remove these blank pages, before the excel is generated?
Without checking your spreadsheet it's impossible to tell from where do those empty pages come from, so can you upload your XLS?
Anyway, do you perhaps have some explicitly defined horizontal or vertical page breaks?
If yes, can you remove the ones you don't need?
Or, do you perhaps have empty columns at the end which have some kind of styling or formatting?
If yes, then you could try using something like this to remove those empty columns from exporting to PDF:
var workbook = ExcelFile.Load("input.xls");
var worksheet = workbook.Worksheets.ActiveWorksheet;
worksheet.NamedRanges.SetPrintArea(
worksheet.GetUsedCellRange(true));
var options = new PdfSaveOptions();
options.SelectionType = SelectionType.ActiveSheet;
workbook.Save("output.pdf", options);
I had a counter of the rows of the document I was writing on, thanks to the help of #Mario Z, I use this function, before the save and solve my problem of blank pages
wsimgs.NamedRanges.SetPrintArea(wsimgs.Cells.GetSubrange("A1",CellRange.RowColumnToPosition (countRow, 10)));

DataGridView column aligment

I use Visual-Studio-2012. Basically I have 5 column DataGridView with product,quantity,price,+,- and I would like to align all text of products I put into my basket as MiddleCentered except actual Product description (it stays MiddleLeft as default).
I can change aligment via RowHeadersDefaultCellStyle, but I can't choose which columns I would like to align and it makes all of them MiddleCentered.
Is there any way to do so? I was trying to search on the NET, but didn't find anything clear. Help would be very appreciated.
As you have not posted your code, here is a way to aligning the text,
dataGridView1.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
Give a try and if you still not able to align the text, please post your code.
Holly spirit, I found the answer. I can change it via Edit Columns, selecting column and changing aligment. How stupid do I feel now. Damn...Sorry to bother guys.

Excel Doc after c# modifications: Ctrl + DownArrow is not working properly

guys!
After I create Excel document in my c# application the Ctrl+DownArrow combination doesn't work properly.
It goes to the last row in the current column. So looks like it means all sheet as one data region WITHOUT empty cells.
so I guess empty cells in my excel sheet aren't empty for Excel.
How to figure it out?
Thank you,
Try creating a macro of what you want to happen. Then look at the macro code which is based off of interops calls. See if it sheds a light on your issue and how to resolve.
Just filter out the "Blanks" Ctrl+Down Arrow and all the blank cells would be selected, now press delete (From key board).
DONE. Now you can jump between entries with Ctrl+Down Arrow.

DevExpress WPF Grid export to excel - additional rows

I have a DevExpress WPF grid (version 9.3). When I export to excel, it has horrible additional rows* that completely mess up excel's functionality such as auto filter.
I've been trying to make sense of the documentation and I think that the solution may lie in setting TableView.PrintCellStyle somehow. But it's really not clear.
I am using the TableView.ExportToXls(string path); method.
Is there a quick way of switching off this behaviour and getting a working xls file?
*I understand that this is to help with creating a spreadsheet that looks the same as the grid. Horrible default behaviour - a working spreadsheet is more important than it looking like the UI.
EDIT: #DmitryG - I have tried this and now, instead of three lines I now get two. Better, but not solved.
I have also checked the KB article you cited and get the following result:
I am using version 9.3.6.
Anything else I can try?
EDIT 2: Have tried the value converter approach. Getting the same additional row.
Worst case, is there anyway of excluding these columns from the export?
As far as I can see the problem like yours was already discussed here:
Exporting Boolean Values causes Three Merged Rows To Appear for each Row of data.
The problem solution for version 9.3 was the direct assigning of the GridColumn.EditSettings property:
<dxg:GridColumn x:Name="Boolean" FieldName="Boolean">
<dxg:GridColumn.EditSettings>
<dxe:CheckEditSettings HorizontalContentAlignment="Center"/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Please also review the following KB article:
How to change representation of data cells via PrintCellStyle when printing/exporting grid data.
P.S. This problem is absent in the latest versions.
DevExpress has significantly improved the export engine in the latest version 14.2 and now the issue should be solved.
 
Please refer to the following help article for more information:
 
Printing and Exporting
I was still getting the additional rows. The quickest and easiest way to get around this was to set the EditSettings of the column so it exports 'True' or 'False', export the grid then set the column back to a checkbox.
Thusly:
public void ExportGridToExcel()
{
TableView.Grid.Columns["*FieldName*"].EditSettings = new TextEditSettings();
TableView.ExportToXls(#"C:\temp\spreadsheet.xls");
TableView.Grid.Columns["*FieldName*"].EditSettings = new CheckEditSettings();
}
NB It's the fieldname the column is bound to and NOT the column name. That caught me out for a minute.

Add a column to PdfPTable, iTextSharp

I'm creating a PDF document using iTextSharp. I see how to create a new table with a number of columns but I can't see anyway to dynamically add a new column. The problem I have is I'm not going to know the number of columns I need straight away, so need to keep adding them
Can somebody please enlighten me or am I going to have to re-create the table each time I need to add a column?
Thanks
Mat
Wouldn't it then make sense to create an intermediate model which contains the table you want, and is capable of then creating the PDF table for you?
I know it sounds like a lot of work, but in the long run it should help in that you would be able to dynamically alter the rows and columns as you build them, and then at the end, simply "compile" the table and spit out the PdfPTable object?
PdfPTable tables are immutable as far as column count goes once created.
The only workaround I can think of is to start with a Whole Bunch of columns and... nope that won't work either. You cannot even add cells to an existing row. I was thinking you could play around with the column spanning to mask your extra columns and adjust them as you added more cells to the rows, but that won't work either.
You must rebuild the table when adding columns. No way around it.
I strongly recommend you figure out how to determine your column count before creating the table in the first place... even if you have to "dry run" through your data. Use some intermediate format (String[][] or whatever) to keep your data, then build the table from that, not the data as it comes to you. Or at least track how many columns you'll need.
Given a huge amount of data, a single pass may not be practical/possible. But rebuilding your whole table several times can't be much better. That's really a performance tuning question that only you have the information to answer.
ITextSharp tables work in a different way to HTML tables (which I guess you're used to).
All you need to tell it is the number of columns you have and then keep adding cells.
Say you create a pdfptable with 5 columns. The 5th cell you add will be on the first row and the 6th cell will be in the 1st column on your 2nd row.
The only downside to this is if you need to add rows where not all the cells are populated but I usually get around this by just adding an empty cell or a cell with a space in it.

Categories