Aspose C# DOCX ignoring table Cell width and height - aspose.words

I am trying to specify the width and height of my tables.
The ultimate goal is for the first column to take up about 90% and the last column to take the remaining 10%.
I have tried many different combinations, but word seems to ignore it.
My Document Builder code is here:
var table = docBuilder.StartTable();
docBuilder.InsertCell();
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90);
docBuilder.CellFormat.ClearFormatting();
docBuilder.Font.Bold = true;
docBuilder.Font.Name = Stylings.TITLEFONT;
docBuilder.Font.Size = Stylings.TITLESIZE1;
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
docBuilder.Write("Description");
var cell = docBuilder.InsertCell();
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10);
docBuilder.CellFormat.FitText = false;
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
docBuilder.Font.Name = Stylings.TITLEFONT;
docBuilder.Font.Size = Stylings.TITLESIZE1;
docBuilder.Font.Bold = true;
docBuilder.Write("Amount (inc GST)");
docBuilder.EndRow();
docBuilder.InsertCell();
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90);
docBuilder.Font.Bold = false;
docBuilder.Font.Name = Stylings.NORMALFONT;
docBuilder.Font.Size = Stylings.NORMALSIZE1;
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
docBuilder.Write(description);
docBuilder.InsertCell();
docBuilder.RowFormat.HeightRule = HeightRule.AtLeast;
docBuilder.RowFormat.Height = 5;
docBuilder.CellFormat.FitText = false;
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10);
docBuilder.Font.Bold = false;
docBuilder.Font.Name = Stylings.NORMALFONT;
docBuilder.Font.Size = Stylings.NORMALSIZE1;
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
docBuilder.Write(total.ToString("C"));
docBuilder.EndRow();
docBuilder.InsertCell();
docBuilder.RowFormat.HeightRule = HeightRule.Auto;
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90);
docBuilder.InsertCell();
docBuilder.CellFormat.FitText = false;
docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10);
docBuilder.Font.Bold = false;
docBuilder.Font.Name = Stylings.NORMALFONT;
docBuilder.Font.Size = Stylings.NORMALSIZE1;
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
docBuilder.Write(total.ToString("C"));
docBuilder.EndRow();
//Table Formatting
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
table.PreferredWidth = PreferredWidth.FromPercent(100);
docBuilder.EndTable();

Please use following sample code snippet to create table with different relative sized cells.
I work with Aspose as developer evangelist.
// Insert a table row made up two cells which have different preferred widths.
Table table = builder.StartTable();
// Insert a relative ( 90 percent) sized cell.
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90);
builder.CellFormat.ClearFormatting();
builder.Font.Bold = true;
builder.Font.Name = "Arial";
builder.Font.Size = 10;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("Description");
// Insert a relative ( 10 percent) sized cell.
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10);
builder.CellFormat.ClearFormatting();
builder.Font.Bold = true;
builder.Font.Name = "Arial";
builder.Font.Size = 10;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("Amount (inc GST)");
builder.EndRow();
// Insert a relative ( 90 percent) sized cell.
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90);
builder.CellFormat.ClearFormatting();
builder.Font.Bold = true;
builder.Font.Name = "Arial";
builder.Font.Size = 10;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("Aspose.Words for .NET 17.10");
// Insert a relative ( 10 percent) sized cell.
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10);
builder.CellFormat.ClearFormatting();
builder.Font.Bold = true;
builder.Font.Name = "Arial";
builder.Font.Size = 10;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("1000.00");
builder.EndRow();

Related

Can you resize images that are passed to UIPrintInteractionController.PrintingItems?

I'm trying to print multiple labels using UIPrintInteractionController.PrintingItems but when the image is loaded it fills the page, is it possible to have multiple images on one page using this method or is there another method that would offer me a better solution? Thanks.
void Print()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
//UIPrintFormatter formatter = new UIPrintFormatter()
//{
// StartPage = 0,
// ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
// MaximumContentWidth = 6 * 72,
//};
int labelAmount = 10;
int x;
NSObject[] labelItems = new NSObject[labelAmount];
for (x = 0; x < labelAmount; x++)
{
labelItems[x] = UIImage.FromFile("Images/BMcAzurri.png");
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
//printer.PrintFormatter = formatter;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) => {
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
}
There are a few ways to do what you are asking, here is just one using a graphics context to do your print page rendering.
Load your image into a UIImage instance
You might want to pre-scale/re-scale that image
Create a UIView that is large enough to contain all your rows and columns of that image
Create a UIImageView that contains your image for each row/column on your "printed page" and place it at the correct location in this view
Using an Image render context, convert the UIView that contains your images to a UIImage and queue and print as many of those as you need...
Example:
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
var uiImage = UIImage.FromFile("BingWallpaper-2017-05-04.jpg");
var noColumns = 2;
var noRows = 2;
var gapBetweenImages = 25;
int noOfPages = 2;
NSObject[] labelItems = new NSObject[noOfPages];
for (int x = 0; x < noOfPages; x++)
{
var aPrintView = new UIView
{
Frame = new CGRect(0, 0, (uiImage.Size.Width * noColumns) + ((noColumns + 1) * gapBetweenImages), (uiImage.Size.Height) * noRows + ((noRows + 1) * gapBetweenImages))
};
for (int column = 0; column < noColumns; column++)
{
for (int row = 0; row < noRows; row++)
{
var printImage = new UIImageView(uiImage)
{
Frame = new CGRect((column * gapBetweenImages) + (column * uiImage.Size.Width), (row * gapBetweenImages) + (row * uiImage.Size.Height), uiImage.Size.Width, uiImage.Size.Height)
};
aPrintView.Add(printImage);
}
}
UIGraphics.BeginImageContext(aPrintView.Bounds.Size);
aPrintView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
var aPageImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
labelItems[x] = aPageImage;
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) =>
{
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
Note: !!! This is not handling the clean up, make sure you Dispose of everything after you are done...
Note: This is just a quick example does not handle the aspect ratio of the image to the paper size, you would need to consider that depending upon what you are printing and to what type of printer/paper...
Note: If you were renderering a number of text fields vs. images, you might want to render to a PDF vs a UIImage and print that instead.

How to delete all items if i delete one of them in tableview?

I Have two collectionView
one is for main items and other is for Sub Items
Main Item we can consider as iPhone
Sub Items we can consider as headphone of apple
so we can say this two items “One Group”
both items are adding at DidSelectMethod and displaying in tableView
i have one option of delete this item
my requirement is if i delete any of one item from this group my all tableview data should be cleared
Here is the Code i am using to delete Product
//Define Button Action in cellForRowAtIndexPath
cell.btnDelete.addTarget(self, action:#selector(ViewController.btnDeleteTapped(_:)), forControlEvents: .TouchUpInside)
cell.btnDelete.tag = indexPath.row
//Button Action
func btnDeleteTapped(sender: UIButton){
self.arrProductCart.removeObjectAtIndex(sender.tag)
self.tblCart.reloadData()
}
MainProduct Array
(
{
"addtional_price" = 0;
"barcode_image" = ".png";
"cart_unique_id" = 6;
"chicken_product" = all;
"created_by" = 2;
"created_date" = "2015-11-19 21:39:24";
"deleted_date" = "0000-00-00 00:00:00";
ids = 151;
isFromMain = 1;
"is_deleted" = 0;
"is_has_addtional_price" = 0;
"parent_product_unique_id" = 6;
"product_id" = 53;
"product_name" = "Black Pepper Chicken";
"product_parent_id" = 0;
"product_price" = "7.9";
"sub_category_type" = "";
"update_date" = "2016-06-22 17:54:53";
"updated_by" = 7;
"parent_product_unique_id" = 6
}
)
SubProduct Array
{
"created_by" = 2;
"created_date" = "2015-11-19 23:11:37";
"deleted_date" = "0000-00-00 00:00:00";
ids = 157;
isFromMain = 0;
"product_category_id" = 16;
"product_description" = "Potato";
"product_id" = 59;
"product_name" = "Potato";
"product_parent_id" = 0;
"product_price" = 2;
"product_quantity" = 0;
"sub_category_type" = s;
"product_unique_id" = 6
}
it that any solution to do this ?

How to get the battery temperature details in iOS?

I am getting battery status and others .
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];
int batinfo=(batLeft*100);
NSLog(#"Battry Level is :%d and Battery Status is :%d",batinfo,i);
switch (i)
{
case UIDeviceBatteryStateUnplugged:
{
break;
}
case UIDeviceBatteryStateCharging:
{
break;
}
case UIDeviceBatteryStateFull:
{
break;
}
default:
{
break;
}
}
Now i am trying to get the temperature details is it possible to get the battery temperature from device .
That is not possible and there is no public API to find . but I found the some answers in here May be it helps you , see once. But some private API you can get this details.
sample app you cannot use this if you deploy your app on the Apple Store, but it can be useful when deploying to TestFlight
Brother I gone through the answer for your question and which indicates that you can get and generally it shows the following states
Battery design capacity
Battery current raw capacity (in mAh)
Battery cycle count
Current battery temperature
Current battery voltage
Current battery discharge rate (device power consumption), in mA
Also following shows the results of battery
{
AdapterDetails = {
Amperage = 1000;
Description = "usb host";
FamilyCode = "-536854528";
PMUConfiguration = 1000;
Watts = 5;
};
AdapterInfo = 16384;
Amperage = 1000;
AppleRawCurrentCapacity = 1279;
AppleRawMaxCapacity = 1275;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryData = {
BatterySerialNumber = REDACTED;
ChemID = 355;
CycleCount = 524;
DesignCapacity = 1420;
Flags = 640;
FullAvailableCapacity = 1325;
ManufactureDate = REDACTED;
MaxCapacity = 1273;
MfgData = REDACTED;
QmaxCell0 = 1350;
StateOfCharge = 100;
Voltage = 4194;
};
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 52;
BootCapacityEstimate = 2;
BootVoltage = 3518;
CFBundleIdentifier = "com.apple.driver.AppleD1815PMU";
ChargerConfiguration = 990;
CurrentCapacity = 1275;
CycleCount = 524;
DesignCapacity = 1420;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 1;
IOClass = AppleD1815PMUPowerSource;
IOFunctionParent64000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOInterruptControllers = (
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000
);
IOInterruptSpecifiers = (
<03000000>,
<26000000>,
<04000000>,
<24000000>
);
IOMatchCategory = AppleD1815PMUPowerSource;
IOPowerManagement = {
CurrentPowerState = 2;
DevicePowerState = 2;
MaxPowerState = 2;
};
IOProbeScore = 0;
IOProviderClass = AppleD1815PMU;
InstantAmperage = 0;
IsCharging = 0;
Location = 0;
Manufacturer = A;
MaxCapacity = 1275;
Model = "0003-A";
Serial = REDACTED;
Temperature = 2590;
TimeRemaining = 0;
UpdateTime = 1461830702;
Voltage = 4182;
"battery-data" = {
"0003-default" = <...>;
"0004-default" = <...>;
"0005-default" = <...};
"built-in" = 1;
}
Above things are from UIDeviceListener
I run with sample code I got below temparature
in EEPowerInformation.m class I put the breakpoint and check that.It is called and brings all information about battery.
- (void) listenerDataUpdated: (NSNotification *) notification
{
latestPowerDictionary = notification.userInfo;
NSLog(#"The latest Power Dictionary is - %#",latestPowerDictionary);
NSLog(#"The battery Temperature is - %#",[latestPowerDictionary objectForKey:#"Temperature"]);
if (self.delegate != nil)
[self.delegate powerInformationUpdated: self];
}
The Printed Statements are
The latest Power Dictionary is - {
AdapterDetails = {
Amperage = 1000;
Description = "usb host";
FamilyCode = "-536854528";
PMUConfiguration = 970;
Watts = 5;
};
AdapterInfo = 16384;
Amperage = 1000;
AppleChargeRateLimitIndex = 0;
AppleRawBrickIDVoltages = (
(
39,
420
)
);
AppleRawCurrentCapacity = 1084;
AppleRawExternalConnected = 1;
AppleRawMaxCapacity = 1221;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 673;
BootCapacityEstimate = 29;
BootVoltage = 3810;
CFBundleIdentifier = "com.apple.driver.AppleARMPlatform";
ChargerConfiguration = 900;
CurrentCapacity = 1222;
CycleCount = 343;
DesignCapacity = 1430;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 0;
IOClass = AppleARMPMUCharger;
IOFunctionParent5E000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOMatchCategory = IODefaultMatchCategory;
IONameMatch = charger;
IONameMatched = charger;
IOPowerManagement = {
CapabilityFlags = 32832;
CurrentPowerState = 2;
DevicePowerState = 2;
MaxPowerState = 2;
};
IOProbeScore = 1000;
IOProviderClass = IOService;
InstantAmperage = 198;
IsCharging = 1;
Location = 0;
Manufacturer = A;
MaxCapacity = 1300;
Model = "0003-A";
Temperature = 3120;
TimeRemaining = 67;
UpdateTime = 1470665642;
Voltage = 4188;
"built-in" = 1;
}
Finally the Printed result of battery Temperature is
The battery Temperature is - 3120
if you don't need temperature number then it is useful to use ThermalState api
https://developer.apple.com/documentation/foundation/nsprocessinfothermalstate?language=objc

JSON object data to UILabel

How can I populate a few UILabels on a ViewController from the JSON object I receive from a previously passed id parameter? I get the response from the server but, I don't know how to populate the key/value pairs to a UILabel.
The JSON response I get is:
{
product = {
attributes = (
);
"average_rating" = "0.00";
backordered = 0;
"backorders_allowed" = 0;
"button_text" = "";
"catalog_visibility" = visible;
categories = (
);
"created_at" = "2016-02-23T05:00:55Z";
"cross_sell_ids" = (
);
description = "<p>Microsoft Office</p>\n";
dimensions = {
height = "";
length = "";
unit = in;
width = "";
};
"download_expiry" = 0;
"download_limit" = 0;
"download_type" = "";
downloadable = 0;
downloads = (
);
featured = 0;
"featured_src" = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
"grouped_products" = (
);
id = 15;
images = (
{
alt = "";
"created_at" = "2016-02-23T05:01:35Z";
id = 16;
position = 0;
src = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
title = "softwarecontract-150×150";
"updated_at" = "2016-02-23T05:01:35Z";
}
);
"in_stock" = 1;
"managing_stock" = 0;
"menu_order" = 0;
"on_sale" = 1;
parent = (
);
"parent_id" = 0;
permalink = "https://qashop.taxometry.com/wordpressv4/product/software-contract/";
price = 25;
"price_html" = "<del><span class=\"amount\">$30.00</span></del> <ins><span class=\"amount\">$25.00</span></ins>";
"product_url" = "";
"purchase_note" = "";
purchaseable = 1;
"rating_count" = 0;
"regular_price" = 30;
"related_ids" = (
);
"reviews_allowed" = 1;
"sale_price" = 25;
"shipping_class" = "";
"shipping_class_id" = "<null>";
"shipping_required" = 1;
"shipping_taxable" = 1;
"short_description" = "";
sku = 2370;
"sold_individually" = 0;
status = publish;
"stock_quantity" = "<null>";
tags = (
);
"tax_class" = "";
"tax_status" = taxable;
taxable = 1;
title = "Software Contract";
"total_sales" = 5;
type = simple;
"updated_at" = "2016-02-23T05:01:41Z";
"upsell_ids" = (
);
variations = (
);
virtual = 0;
visible = 1;
weight = "<null>";
};
}
Try this - > First
then Second

Export to excel losses leading zero in mvc4

i am working on mvc4 project.I have having issue with export to excel code.I have employee id that is varchar field... and have leading zero ie : 0289707,2909878 etc..
So when i export data to excel it looses leading zero..
So how do i export data as it is ??
Controller code is as below :
public ActionResult ExportToExcel(string strStartDate, string strEndDate)
{
try
{
GridView gridView = new GridView();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "EmployeeReport " + Helper.GetBrazilTime(DateTime.UtcNow).ToString() + ".xls"));
Response.ContentType = "application/ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
gridView.AllowPaging = false;
DateTime startDate = Convert.ToDateTime(strStartDate);
DateTime endDate = Convert.ToDateTime(strEndDate);
if (Helper.CurrentCulture == "pt-BR")
{
startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, DateTimeKind.Utc);
endDate = new DateTime(endDate.Year, startDate.Month, endDate.Day, 0, 0, 0, DateTimeKind.Utc);
}
gridView.DataSource = ReportExecutor.GetEmployeeReportExportData(startDate, endDate);
gridView.DataBind();
//This will change the header background color
gridView.HeaderRow.Style.Add("background-color", "#FFFFFF"); //
//This will apply style to gridview header cells
for (int index = 0; index < gridView.HeaderRow.Cells.Count; index++)
{
gridView.HeaderRow.Cells[index].Style.Add("background-color", "#778899"); //Light Slate Gray
gridView.HeaderRow.Cells[index].Style.Add("foreground-color", "#ffffff"); // White
}
gridView.HeaderRow.Cells[0].Text = #Resources.Resource.ShopName;
gridView.HeaderRow.Cells[1].Text = #Resources.Resource.MachineName;
gridView.HeaderRow.Cells[2].Text = #Resources.Resource.ProjectIDName;
gridView.HeaderRow.Cells[3].Text = #Resources.Resource.BaseActivity;
gridView.HeaderRow.Cells[4].Text = #Resources.Resource.EmployeeID;
gridView.HeaderRow.Cells[5].Text = #Resources.Resource.EmployeeName;
gridView.HeaderRow.Cells[6].Text = #Resources.Resource.RunTime;
gridView.HeaderRow.Cells[7].Text = #Resources.Resource.SetUp;
gridView.HeaderRow.Cells[8].Text = #Resources.Resource.TearDown;
gridView.HeaderRow.Cells[9].Text = #Resources.Resource.Work;
gridView.HeaderRow.Cells[10].Text = #Resources.Resource.Rework;
gridView.HeaderRow.Cells[11].Text = #Resources.Resource.LunchHours;
gridView.HeaderRow.Cells[12].Text = #Resources.Resource.MaintenanceHours;
gridView.HeaderRow.Cells[13].Text = #Resources.Resource.QualityProblemHours;
gridView.HeaderRow.Cells[14].Text = #Resources.Resource.LOMHours;
gridView.HeaderRow.Cells[15].Text = #Resources.Resource.UDCIdle;
gridView.HeaderRow.Cells[16].Text = #Resources.Resource.UDCOthers;
gridView.HeaderRow.Cells[17].Text = #Resources.Resource.ActualShiftHours;
gridView.HeaderRow.Cells[18].Text = #Resources.Resource.Overtime;
int index2 = 1;
//This will apply style to alternate rows
foreach (GridViewRow gridViewRow in gridView.Rows)
{
//gridViewRow.Attributes.Add("class", "textmode");
gridViewRow.BackColor = Color.White;
if (index2 <= gridView.Rows.Count)
{
if (index2 % 2 != 0)
{
for (int index3 = 0; index3 < gridViewRow.Cells.Count; index3++)
{
gridViewRow.Cells[index3].Style.Add("background-color", "#e6e6fa");// Lavender
//gridViewRow.Cells[index3].Style.Add("class", "textmode");// Apply text style to all rows
}
}
}
index2++;
}
gridView.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
catch
{
}
return null;
}
For i As Integer = 0 To GridView1.Rows.Count - 1
//Apply text style to each Row.cell
//The attribute must be "text" not "textmode" and it must be applied to the cells
For j As Integer = 0 To GridView1.Rows(i).Cells.Count - 1
GridView1.Rows(i).Cells(j).Attributes.Add("class", "text");
Next
Next

Resources