How do I stop ReSharper from placing "x => new" on a new line? - resharper

I know this is a fairly small detail, but for some reason it's incredibly annoying to me and I cannot figure out how to correct it (I've looked at the "Line Breaks and Wrapping" options).
Here's how I like this code formatted:
var reps = ctx.Commissions
.GroupBy(x => x.SalesRep)
.Select(x => new
{
x.Key.UserID,
Name = x.Key.FirstName + " " + x.Key.LastName
})
.ToList();
ReSharper, though, likes to format it as
var reps = ctx.Commissions
.GroupBy(x => x.SalesRep)
.Select(
x => new
{
x.Key.UserID,
Name = x.Key.FirstName + " " + x.Key.LastName
})
.ToList();
Any ideas as to how I can stop ReSharper from doing this?
Thank you,
Andrew

It looks like you should disable Prefer wrap after '(' in invocation option in Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping section.

Related

Official API or way to get the current separator setting (e.g., `,` or `;`) of Excel formulas

As there are already more than 1000 Office JavaScript APIs, I would like to know if there is an official API or way to get the current separator setting (e.g., , or ;) of Excel formulas.
Determining it from a formula is not always possible, for example, in a workbook without any formulas.
Unfortunately, Office JS Excel API currently doesn't have API to get separator for the formulas based on the locale. therefore, I would suggest that you could submit the request and upvote this request at uservoice
But to unblock your scenario, you could consider a workaround, detect the locale using cultureInfor.name from cultureInfo and figure out separator accordingly.
Here is the sample code for your reference:
await Excel.run(async (context) => {
var app = context.workbook.application;
var ci = app.cultureInfo;
ci.load("name");
await context.sync();
var seperator;
if (ci.name = "en-US")
seperator = ","
else if (ci.name = "de-DE")
seperator = ";"
// continue determine the separator by other locale
console.log("Culture: " + ci.name + " and Seperator: " + seperator);
});

Enable and disable multiple buttons in Visual C++

I'm trying to enable and disable multiple button for years 2016 to 2005, it named as But2016 to But2005, in my C++ program but it didn't work:
when I assigned a variable within a name, like:
But+"&i"->Enable = false;
it appeared an error that But undeclared. And, when I tried to use indirect variable, it didn't work, like:
RadioButton^ But = (gcnew System::Windows::Forms::RadioButton());
for (i = 2016; i > 2004; i--)
{
But->Name = "But" + (i);
textBox1->Text = But->Name->ToString();
But->Enabled = false;
}
How to solve this issue?
You can't combine Strings together to make new variable names. However, it should be possible to enter the buttons into a container of some sort and iterate over it using a loop.
Below is some pseudocode. Please bear in mind that this is not written in C++, but something like this should be possible:
Map buttons = new HashMap();
buttons.add(2005, But2005);
buttons.add(2006, But2006);
... // add all buttons
for (Integer i in buttons) {
if (i >= 2005 && i <= 2016) {
buttons.get(i).disable();
}
}

Displaying a computed field with multiple lines? (xpages)

OK, I have a customer name and address and simply want to display this in one computed field instead of separate lines in a table to save real estate. I've tried several iterations of #newline but to no avail. Can someone give me some guidance?
I would also like to NOT include Address2 if it's blank. I'm new to javascript. Thanks for your help.
var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
var d = #Char(13);
a + #NewLine() + b + "<br>" + c;
Set property escape="false" in computed field and add <br /> whenever you want a newline.
You can set this property in properties tab selecting content type "HTML" too:
Your code would be
var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
a + "<br />" + b + (c ? "<br />" + c : "");
Mike,
I had to do nearly the same thing recently and used a Multiline Edit Box. Place your same code in data section of an <xp:inputTextArea> (Multiline Edit Box in palette) and then make it read-only.

Excel is stripping leading 0's from CSV files

It believe that Excel is stripping leading 0s. I was told that updating the column format to text during the export will fix this and to modify Excel output (coming from "ProofAndTracking actionIpromoteuAutomation" file, yet I can't find this file or how to access where the excel formatting code is generated).
I've never worked with Excel. I tried this, but it seems to be a local fix:
http://excelribbon.tips.net/T010262_Handling_Leading_Zeros_in_CSV_Files.html
Could someone point me in the right direction to start?
I've researched these answers How to stop the leading 0's from being stripped off when exporting to excel from a datatable? and Export Excel : Avoid stripping the leading zeros
Thanks in advance!
Here is the function I believe is causing the problem, but not sure yet how to format columns to text here. /*
* format and send order and tracking info (via Excel spreadsheet) for the day for ipromoteu (150837)
*/
public function actionIpromoteuAutomation() {
$ordersGroup1 = $this->getIpromoteuProof();
$ordersGroup2 = $this->getIpromoteuProofHistory();
$orders = array_merge($ordersGroup1, $ordersGroup2);
$fileName = 'Hit Promo Order Tracking ' . date('m-d-Y');
$this->_export($orders, $fileName);
$fileName = $fileName . '.xls';
$toIPROMOTEU = array(//email to be sent to HR when request is submitted
'body' => 'Attached, please find the Excel spreadsheet containing'
. ' order details for orders on ' . date('m/d/Y') . '.',
'from_email' => 'donotreply#hitpromo.net',
'from_name' => 'Hit Promotional Products',
'subject' => 'Order Tracking Information - ' . date('m/d/Y'),
'to_emails' => 'orders#ipromoteu.com',
'attachments' => array(array('path' => Yii::app()->basePath . '/../tmp/' . $fileName, 'filename' => $fileName)),
);
Hit::email((object) $toIPROMOTEU);
$this->logForDeveloper('Order records sent to iPromoteU for '. date('m/d/Y'));
}
private function _export($data, $fileName, $format = 'excel', $output = false) {
// get a reference to the path of PHPExcel classes
$phpExcelPath = Yii::getPathOfAlias('ext.phpexcel');
// Turn off our yii library autoload
spl_autoload_unregister(array('YiiBase', 'autoload'));
include($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
if ($format == 'excel') {
// Set properties
$objPHPExcel->getProperties()->setCreator(Yii::app()->user->name)
->setLastModifiedBy(Yii::app()->user->name)
->setTitle('Order Tracking Report');
}
$styleArray = array(
'font' => array(
'bold' => true,
'underline' => true,
)
);
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
for ($rowCounter = 0; $rowCounter < sizeof($data); $rowCounter++) {
$sheet->getStyle("A" . ($rowCounter + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$sheet->getStyle("B" . ($rowCounter + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$sheet->getStyle("C" . ($rowCounter + 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$sheet->setCellValue("A" . ($rowCounter + 1), date('m/d/Y', strtotime($data[$rowCounter]['date'])));
//$sheet->setCellValue("A".($rowCounter+1), $data[$rowCounter]['date']);
if ($data[$rowCounter]['fedex_tracking'] != '')
$sheet->setCellValue("B" . ($rowCounter + 1), $data[$rowCounter]['fedex_tracking']);
else
$sheet->setCellValue("B" . ($rowCounter + 1), $data[$rowCounter]['other_tracking']);
$sheet->setCellValue("C" . ($rowCounter + 1), $data[$rowCounter]['sales_order_number']);
$sheet->getStyle("B" . ($rowCounter + 1))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
}
$sheet->setCellValue("A1", "DATE")
->setCellValue("B1", "TRACKING")
->setCellValue("C1", "PO NUMBER")
->getStyle("A1:C1")->applyFromArray($styleArray);
////Set the column widths
$sheet->getColumnDimension("A")->setWidth(25);
$sheet->getColumnDimension("B")->setWidth(25);
$sheet->getColumnDimension("C")->setWidth(25);
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Order Tracking Report');
// Set active sheet index to the first sheet,
// so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$fileName = $fileName . ($format == 'excel' ? '.xls' : '.csv');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$path = Yii::app()->basePath . '/../tmp/' . $fileName;
$objWriter->save($path);
// Once we have finished using the library, give back the
// power to Yii...
spl_autoload_register(array('YiiBase', 'autoload'));
}
public function getIpromoteuProof() {
$date = date('Ymd');
$db2params = Yii::app()->params['db2params'];
$db = Zend_Db::factory('Db2', $db2params);
$select = $db->select()
->from(
// table
array('t' => 'WBPIPRAE'),
// columns
array(
'sales_order_number' => 'TRIM(WAESPO#)',
),
// schema
$db2params['schemas']['hitdta'])
->joinLeft(
// table
array('f' => 'MFD1MD'), 'CONCAT(TRIM(WAEORD#),RIGHT(TRIM(MDORDR),3))=TRIM(MDORDR)',
// columns
array(
'fedex_tracking' => 'TRIM(MDFTRK)',
'other_tracking' => 'TRIM(MDFBRC)',
'date' => 'TRIM(MDUPDT)',
),
// schema
$db2params['schemas']['varfil'])
->where("MDUPDT = '" . $date . "'")
->where("WAEIVKY='150837'")
->order('sales_order_number')
->distinct(true);
$stmt = $db->query($select);
$orders = $stmt->fetchAll();
return $orders;
}
OK, Excel can create the csv columns as text but the issue is with the import.
When Excel opens csv files it 'helpfully' converts anything that looks like a number to a number, stripping leading zero's.
First make sure Excel is exporting it as it should, open the file in a text editor and check the leading zero is present.
You will probably have to change how the file is imported. Instead of them just double clicking the csv file, they need to run through the data import wizard:
Import 'From Text'
Select Delimited
Make sure comma is ticked
Select column as text
This should resolve the problem on the other side.
Another alternative is to add a single apostrophe ' before the numbers, however if they use macros/software to interact with the file this might break that.
Edit
After looking at the PHP code (I can't test) you might be able to change the line:
$sheet->getStyle("B" . ($rowCounter + 1))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
To:
$sheet->getStyle("B" . ($rowCounter + 1))->getNumberFormat()->setFormatCode('000000000000'); // With however many zero's you need to keep
This however may still get removed when you export as it's still technically a number and formatting will be removed.

Unable to fill Content Control in Word using OpenXML

i am new to OpenXML and i am about to pull my hair on this issue. Help would really appreciated.
Overview is that i am trying to fill the word document content template thru asp.net.
I was easily able to populate the fields using CustomXML, BUT THE document i am trying to fill is also mapped with SharePoint document library. So when i upload the document in SharePoint library it will auto populate the columns from the content controls on Word document. Now using custom XML is ruining that setting. And using OpenXML to fill data is not working when the controls are mapped to SharePoint.
Please help with sample code or the right direction.
This is exactly what we did in our project:) lucky you.
first you need to create event receiver for that document library. and you need to implement ItemUpdated and ItemAdded. see
http://www.dotnetcurry.com/ShowArticle.aspx?ID=649
http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx
//code for event receiver.. This will give you name of content control and its values
Dictionary<string, string> results = new Dictionary<string, string>();
using (Stream stream = file.OpenBinaryStream(SPOpenBinaryOptions.SkipVirusScan)) {
using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, true)) {
var contentControls = doc.MainDocumentPart
.GetXDocument()
.Descendants(w + "sdt");
foreach ( var contentControl in contentControls )
{
string key = (string)contentControl.Descendants(w + "sdtPr").Elements(w + "alias").Attributes(w + "val").FirstOrDefault();
string val = GetTextFromContentControl(contentControl);
results[key] = val;
}
}
static string GetTextFromContentControl(XElement contentControlNode) {
return contentControlNode.Descendants(w + "p")
.Select
(
p => p.Elements()
.Where(z => z.Name == r || z.Name == ins || z.Name == br)
.Descendants()
.Where(z => z.Name == w + "t" || z.Name == w + "br")
.StringConcatenate(element => (string)element + (element.Name == w + "br" ? Environment.NewLine : "")) + Environment.NewLine
).StringConcatenate();
}

Resources